{"id":2024,"date":"2023-05-23T08:11:02","date_gmt":"2023-05-23T00:11:02","guid":{"rendered":"https:\/\/104.es\/?p=2024"},"modified":"2023-07-21T10:14:35","modified_gmt":"2023-07-21T02:14:35","slug":"unity-timer-counter-basics","status":"publish","type":"post","link":"https:\/\/104.es\/index.php\/2023\/05\/23\/unity-timer-counter-basics\/","title":{"rendered":"\u5728Unity\u5834\u666f\u4e2d\u6dfb\u52a0\u8a08\u6642\u5668\u7684\u7a0b\u5f0f\u7247\u6bb5"},"content":{"rendered":"\n<p>\u4ee5\u4e0b\u9019\u6bb5\u7a0b\u5f0f\u78bc\u53ef\u4ee5\u7528\u4f86\u5728\u756b\u9762\u4e0a\u6dfb\u52a0\u4e00\u500b\u4e0d\u65b7\u986f\u793a\u5df2\u7d93\u904e\u79d2\u6578\u7684\u8a08\u6642\u5668\uff0c\u5047\u8a2d\u4f60\u7684\u6587\u5b57\u7269\u4ef6\u53eb\u505aTextTimeCounter\uff0c\u8acb\u5148\u628a\u5b83\u653e\u5728\u756b\u9762\u4e0a\u4f60\u60f3\u8981\u7684\u5730\u65b9\uff0c\u4e26\u4e14\u628a\u5b83\u62d6\u66f3\u81f3\u9019\u500b\u7a0b\u5f0f\u78bc\u7684\u7269\u4ef6\u6b04\u4f4d\u4e2d\uff0c\u5c31\u53ef\u4ee5\u6b63\u5e38\u904b\u4f5c\u4e86\u3002<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">using System.Collections;\nusing System.Collections.Generic;\nusing UnityEngine;\nusing UnityEngine.UI;\npublic class Counter : MonoBehaviour\n{\n    public Text TimeCounter;\n    \/\/ Start is called before the first frame update\n    void Start()\n    {\n        StartCoroutine(MyCounter());\n    }\n    IEnumerator MyCounter()\n    {\n        while(true)\n        {\n            int current = int.Parse(TimeCounter.text);\n            current++;\n            TimeCounter.text = current.ToString();\n            yield return new WaitForSeconds(1f);\n        }\n    }\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9019\u6bb5\u7a0b\u5f0f\u78bc\u53ef\u4ee5\u7528\u4f86\u5728\u756b\u9762\u4e0a\u6dfb\u52a0\u4e00\u500b\u4e0d\u65b7\u986f\u793a\u5df2\u7d93\u904e\u79d2\u6578\u7684\u8a08\u6642\u5668<\/p>\n","protected":false},"author":1,"featured_media":1772,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[18],"tags":[],"class_list":["post-2024","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-unity"],"jetpack_featured_media_url":"https:\/\/104.es\/wp-content\/uploads\/2022\/06\/image-35.png","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/2024","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/comments?post=2024"}],"version-history":[{"count":1,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/2024\/revisions"}],"predecessor-version":[{"id":2160,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/2024\/revisions\/2160"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/media\/1772"}],"wp:attachment":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/media?parent=2024"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/categories?post=2024"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/tags?post=2024"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}