{"id":2104,"date":"2023-06-13T11:43:25","date_gmt":"2023-06-13T03:43:25","guid":{"rendered":"https:\/\/104.es\/?p=2104"},"modified":"2023-07-29T23:06:33","modified_gmt":"2023-07-29T15:06:33","slug":"unity-character-move-sfx","status":"publish","type":"post","link":"https:\/\/104.es\/index.php\/2023\/06\/13\/unity-character-move-sfx\/","title":{"rendered":"\u3010Unity\u3011\u4eba\u7269\u79fb\u52d5\u7684\u8173\u6b65\u8072"},"content":{"rendered":"\n<p>\u6211\u5011\u5728\u4f7f\u7528Invector 3rdPersonController\u6642\uff0c\u5982\u679c\u60f3\u8981\u5728\u89d2\u8272\u79fb\u52d5\u6642\u767c\u51fa\u8173\u6b65\u8072\uff0c\u90a3\u9ebc\u6211\u5011\u53ef\u4ee5\u5beb\u4e00\u500b\u7a0b\u5f0f\uff08\u5728\u6b64\u4f8b\u70baPlayerController\uff09\u653e\u5728\u4f60\u6240\u5efa\u7acb\u7684\u89d2\u8272\u4e2d\uff0c\u8b93\u9019\u500b\u7a0b\u5f0f\u4e0d\u65b7\u5730\u53bb\u5075\u6e2c\u76ee\u524dInputVertical\u9019\u500b\u503c\u662f\u5426\u6709\u4efb\u4f55\u7684\u8b8a\u5316\uff0c\u5982\u679c\u6709\u7684\u8a71\uff0c\u5c31\u64ad\u653e\u8072\u97f3\uff0c\u6c92\u6709\u7684\u8a71\u5c31\u628a\u8072\u97f3\u505c\u6b62\uff0c\u5982\u6b64\u5c31\u53ef\u4ee5\u8b93\u89d2\u8272\u5728\u79fb\u52d5\u7684\u6642\u5019\u591a\u4e86\u8173\u6b65\u8072\u4e86\u3002<\/p>\n\n\n\n<p>\u5148\u770b\u7a0b\u5f0f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System.Collections;\nusing System.Collections.Generic;\nusing UnityEngine;\n\npublic class PlayerControl : MonoBehaviour\n{\n    public Animator GetA;\n    public AudioSource GetAudioSource;\n\n    void Start()\n    {\n        GetA = this.GetComponent&lt;Animator&gt;();\n        GetAudioSource = this.GetComponent&lt;AudioSource&gt;();\n    }\n\n    void Update()\n    {\n        if(GetA.GetFloat(\"InputVertical\") &gt;= 0.4f)\n        {\n            if (!GetAudioSource.isPlaying)\n                GetAudioSource.Play();\n        } else\n        {\n            GetAudioSource.Stop();\n        }\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>\u65b0\u589e\u4e4b\u7a0b\u5f0f\u4ee5\u53caAudioSource\u5143\u4ef6\u7684\u4ecb\u9762\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"298\" height=\"693\" src=\"http:\/\/104es.nkust.org\/wp-content\/uploads\/2023\/06\/image.png?w=298\" alt=\"\" class=\"wp-image-2108\" srcset=\"https:\/\/104.es\/wp-content\/uploads\/2023\/06\/image.png 298w, https:\/\/104.es\/wp-content\/uploads\/2023\/06\/image-129x300.png 129w\" sizes=\"auto, (max-width: 298px) 100vw, 298px\" \/><\/figure>\n\n\n\n<p>\u8a18\u5f97\u8981\u5728AudioSource\u4e0a\u52a0\u5165\u8072\u97f3\u6bb5\uff0c\u4e26\u628aPlay On Awake\u95dc\u9589\uff0c\u4ee5\u53caLoop\u6253\u958b\u5594\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u5011\u5728\u4f7f\u7528Invector 3rdPersonController\u6642\uff0c\u5982\u679c\u60f3\u8981\u5728\u89d2\u8272\u79fb\u52d5\u6642\u767c\u51fa\u8173\u6b65\u8072\uff0c\u90a3\u9ebc\u6211\u5011\u53ef\u4ee5\u5beb\u4e00\u500b\u7a0b\u5f0f\uff08\u5728\u6b64\u4f8b\u70baPlayerController\uff09\u653e\u5728\u4f60\u6240\u5efa\u7acb\u7684\u89d2\u8272\u4e2d\uff0c\u8b93\u9019\u500b\u7a0b\u5f0f\u4e0d\u65b7\u5730\u53bb\u5075\u6e2c\u76ee\u524dInputVertical\u9019\u500b\u503c\u662f\u5426\u6709\u4efb\u4f55\u7684\u8b8a\u5316\uff0c\u5982\u679c\u6709\u7684\u8a71\uff0c\u5c31\u64ad\u653e\u8072\u97f3\uff0c\u6c92\u6709\u7684\u8a71\u5c31\u628a\u8072\u97f3\u505c\u6b62\uff0c\u5982\u6b64\u5c31\u53ef\u4ee5\u8b93\u89d2\u8272\u5728\u79fb\u52d5\u7684\u6642\u5019\u591a\u4e86\u8173\u6b65\u8072\u4e86\u3002<\/p>\n","protected":false},"author":1,"featured_media":2148,"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-2104","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-unity"],"jetpack_featured_media_url":"https:\/\/104.es\/wp-content\/uploads\/2023\/07\/aeyam8un6ny.jpg","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/2104","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=2104"}],"version-history":[{"count":2,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/2104\/revisions"}],"predecessor-version":[{"id":2352,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/2104\/revisions\/2352"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/media\/2148"}],"wp:attachment":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/media?parent=2104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/categories?post=2104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/tags?post=2104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}