{"id":2079,"date":"2023-05-30T08:31:54","date_gmt":"2023-05-30T00:31:54","guid":{"rendered":"https:\/\/104.es\/?p=2079"},"modified":"2023-07-29T23:07:04","modified_gmt":"2023-07-29T15:07:04","slug":"unity-qa-app","status":"publish","type":"post","link":"https:\/\/104.es\/index.php\/2023\/05\/30\/unity-qa-app\/","title":{"rendered":"\u3010Unity\u3011\u554f\u7b54\u984c\u5be6\u4f5c"},"content":{"rendered":"\n<p>\u5982\u679c\u6211\u5011\u60f3\u8981\u4f7f\u7528Unity\u4f86\u5efa\u7acb\u4e00\u500b\u554f\u7b54\u984c\u7684\u5c0f\u6e2c\u9a57\uff0c\u9996\u5148\u8981\u4f48\u7f6e\u597d\u5834\u666f\uff0c\u63a5\u8457\u6e96\u5099\u597d\u60f3\u8981\u554f\u7684\u554f\u984c\u4ee5\u53ca\u9019\u4e9b\u554f\u984c\u7684\u7b54\u6848\u3002\u4ee5\u4e0b\u5c31\u4ee5\u662f\u975e\u984c\u4f5c\u70ba\u7bc4\u4f8b\uff0c\u8aaa\u660e\u5982\u4f55\u5728Unity\u4e2d\u5efa\u7acb\u9019\u6a23\u5b50\u7684\u61c9\u7528\u7a0b\u5f0f\u3002<\/p>\n\n\n\n<p>\u8acb\u5148\u4f48\u7f6e\u597d\u6240\u9700\u8981\u7684\u5834\u666f\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1344\" height=\"804\" src=\"http:\/\/104es.nkust.org\/wp-content\/uploads\/2023\/05\/e688aae59c96-2023-05-30-e4b88ae58d888.24.05.png?w=1024\" alt=\"\" class=\"wp-image-2082\" srcset=\"https:\/\/104.es\/wp-content\/uploads\/2023\/05\/e688aae59c96-2023-05-30-e4b88ae58d888.24.05.png 1344w, https:\/\/104.es\/wp-content\/uploads\/2023\/05\/e688aae59c96-2023-05-30-e4b88ae58d888.24.05-300x179.png 300w, https:\/\/104.es\/wp-content\/uploads\/2023\/05\/e688aae59c96-2023-05-30-e4b88ae58d888.24.05-1024x613.png 1024w, https:\/\/104.es\/wp-content\/uploads\/2023\/05\/e688aae59c96-2023-05-30-e4b88ae58d888.24.05-768x459.png 768w\" sizes=\"auto, (max-width: 1344px) 100vw, 1344px\" \/><\/figure>\n\n\n\n<p>\u9019\u88e1\u9762\u4f7f\u7528\u4e86\u4ee5\u4e0b\u7684\u9019\u4e9b\u7269\u4ef6\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/104es.nkust.org\/wp-content\/uploads\/2023\/05\/e688aae59c96-2023-05-30-e4b88ae58d888.24.52.png?w=510\" alt=\"\" class=\"wp-image-2084\" width=\"311\" height=\"391\" srcset=\"https:\/\/104.es\/wp-content\/uploads\/2023\/05\/e688aae59c96-2023-05-30-e4b88ae58d888.24.52.png 510w, https:\/\/104.es\/wp-content\/uploads\/2023\/05\/e688aae59c96-2023-05-30-e4b88ae58d888.24.52-238x300.png 238w\" sizes=\"auto, (max-width: 311px) 100vw, 311px\" \/><\/figure>\n\n\n\n<p>\u7136\u5f8c\u6e96\u5099\u5169\u652f\u7a0b\u5f0f\uff0c\u5206\u5225\u662fStartConversation\u4ee5\u53caQA\uff0c\u4ee5\u4e0b\u662fStartConversation\u7684\u5167\u5bb9\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System.Collections;\nusing System.Collections.Generic;\nusing UnityEngine;\nusing UnityEngine.UI;\n\npublic class StartConversation : MonoBehaviour\n{\n    public GameObject player;\n    public string&#91;] StartDialog;\n    public Text Dialog;\n    public Image MainBoard;\n    public Image QABoard;\n    public Button LeftButton, RightButton;\n    public Text QAText;\n    private IEnumerator StartChat()\n    {\n  \n        foreach(string sen in StartDialog)\n        {\n            Dialog.text = sen;\n            yield return new WaitForSeconds(3f);\n        }\n        player.SetActive(true);\n        MainBoard.enabled = false;\n        Dialog.enabled = false;\n        QABoard.gameObject.SetActive(true);\n        QAText.gameObject.SetActive(true);\n        LeftButton.gameObject.SetActive(true);\n        RightButton.gameObject.SetActive(true);\n\n    }\n    \/\/ Start is called before the first frameupdate\n    void Start()\n    {\n        LeftButton.gameObject.SetActive(false);\n        RightButton.gameObject.SetActive(false);\n        QAText.gameObject.SetActive(false);\n        QABoard.gameObject.SetActive(false);\n        player.SetActive(false);\n        StartCoroutine(StartChat());\n    }\n\n    \/\/ Update is called once per frame\n    void Update()\n    {\n        \n    }\n}\n<\/code><\/pre>\n\n\n\n<p>\u4ee5\u4e0b\u5247\u662fQA\u7684\u5167\u5bb9\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System.Collections;\nusing System.Collections.Generic;\nusing UnityEngine;\nusing UnityEngine.UI;\nusing UnityEngine.Audio;\n\npublic class QA : MonoBehaviour\n{\n    public AudioSource SoundEffect;\n    public AudioClip&#91;] Soundclips;\n    \n    public GameObject player;\n    public Animator playerAnimator;\n    public Text QAItem;\n    public Text Score;\n    public Image QABoard;\n    public string&#91;] Items;\n    public bool&#91;] Answers;\n    private int index = 0;\n    private int score = 0;\n    public Button LeftButton, RightButton;\n\n    void Start()\n    {\n        QAItem.enabled = true;\n        LeftButton.enabled = true;\n        RightButton.enabled = true;\n        index = 0;\n        score = 0;\n        Score.text = score.ToString();\n        QAItem.text = Items&#91;index];\n        \n    }\n\n    IEnumerator Next()\n    {\n        index++;\n        LeftButton.gameObject.SetActive(false);\n        RightButton.gameObject.SetActive(false);\n        yield return new WaitForSeconds(3f);\n        LeftButton.gameObject.SetActive(true);\n        RightButton.gameObject.SetActive(true);\n        if (index&lt; Items.Length)\n        {\n            QAItem.text = Items&#91;index];\n        }\n        else\n        {\n            QAItem.gameObject.SetActive(false);\n            LeftButton.gameObject.SetActive(false);\n            RightButton.gameObject.SetActive(false);\n            QAItem.gameObject.SetActive(false);\n            QABoard.gameObject.SetActive(false);\n        }\n    }\n\n    public void ButtonYes()\n    {\n        if (Answers&#91;index]) {\n            score += 1;\n            Score.text = score.ToString();\n            playerAnimator.SetTrigger(\"Win\");\n            PlayWinSound();\n        } else\n        {\n            playerAnimator.SetTrigger(\"Lose\");\n            PlayLoseSound();\n        }\n        StartCoroutine(Next());\n\n    }\n\n    public void ButtonNo()\n    {\n        if (!Answers&#91;index])\n        {\n            score += 1;\n            Score.text = score.ToString();\n            playerAnimator.SetTrigger(\"Win\");\n            PlayWinSound();\n        } else\n        {\n            playerAnimator.SetTrigger(\"Lose\");\n            PlayLoseSound();\n        }\n        StartCoroutine(Next());\n    }\n\n    void PlayWinSound()\n    {\n        SoundEffect.clip = Soundclips&#91;0];\n        SoundEffect.Play();\n    }\n\n    void PlayLoseSound()\n    {\n        SoundEffect.clip = Soundclips&#91;1];\n        SoundEffect.Play();\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>\u7531\u65bc\u5728\u7a0b\u5f0f\u4e2d\u4f7f\u7528\u4e86\u8a31\u591a\u7684public\u7269\u4ef6\uff0c\u6240\u4ee5\u7576\u6211\u5011\u5206\u5225\u628aQA\u653e\u5230UnityChan\u4ee5\u53ca\u628aStartConversation\u653e\u5230Main Camera\u4f5c\u70ba\u7d44\u4ef6\u4e4b\u5f8c\uff0c\u9084\u8981\u518d\u62d6\u66f3\u4e00\u4e9b\u7269\u4f5c\u9032\u884c\u9023\u7d50\u3002\u4ee5\u4e0b\u662fMain Camera\u4e2d\u7684StartConversation\u8981\u9023\u7d50\u7684\u7269\u4ef6\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"724\" height=\"626\" src=\"http:\/\/104es.nkust.org\/wp-content\/uploads\/2023\/05\/e688aae59c96-2023-05-30-e4b88ae58d888.29.40.png?w=724\" alt=\"\" class=\"wp-image-2088\" srcset=\"https:\/\/104.es\/wp-content\/uploads\/2023\/05\/e688aae59c96-2023-05-30-e4b88ae58d888.29.40.png 724w, https:\/\/104.es\/wp-content\/uploads\/2023\/05\/e688aae59c96-2023-05-30-e4b88ae58d888.29.40-300x259.png 300w\" sizes=\"auto, (max-width: 724px) 100vw, 724px\" \/><\/figure>\n\n\n\n<p>\u4ee5\u4e0b\u5247\u662f\u5728UnityChan\u4e2d\u7684QA\u6240\u9700\u8981\u7684\u9023\u7d50\u7269\u4ef6\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"746\" height=\"1100\" src=\"http:\/\/104es.nkust.org\/wp-content\/uploads\/2023\/05\/e688aae59c96-2023-05-30-e4b88ae58d888.31.01.png?w=694\" alt=\"\" class=\"wp-image-2090\" srcset=\"https:\/\/104.es\/wp-content\/uploads\/2023\/05\/e688aae59c96-2023-05-30-e4b88ae58d888.31.01.png 746w, https:\/\/104.es\/wp-content\/uploads\/2023\/05\/e688aae59c96-2023-05-30-e4b88ae58d888.31.01-203x300.png 203w, https:\/\/104.es\/wp-content\/uploads\/2023\/05\/e688aae59c96-2023-05-30-e4b88ae58d888.31.01-694x1024.png 694w\" sizes=\"auto, (max-width: 746px) 100vw, 746px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u679c\u6211\u5011\u60f3\u8981\u4f7f\u7528Unity\u4f86\u5efa\u7acb\u4e00\u500b\u554f\u7b54\u984c\u7684\u5c0f\u6e2c\u9a57\uff0c\u9996\u5148\u8981\u4f48\u7f6e\u597d\u5834\u666f\uff0c\u63a5\u8457\u6e96\u5099\u597d\u60f3\u8981\u554f\u7684\u554f\u984c\u4ee5\u53ca\u9019\u4e9b\u554f\u984c\u7684\u7b54\u6848\u3002\u4ee5\u4e0b\u5c31\u4ee5\u662f\u975e\u984c\u4f5c\u70ba\u7bc4\u4f8b\uff0c\u8aaa\u660e\u5982\u4f55\u5728Unity\u4e2d\u5efa\u7acb\u9019\u6a23\u5b50\u7684\u61c9\u7528\u7a0b\u5f0f\u3002<\/p>\n","protected":false},"author":1,"featured_media":2082,"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-2079","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-unity"],"jetpack_featured_media_url":"https:\/\/104.es\/wp-content\/uploads\/2023\/05\/e688aae59c96-2023-05-30-e4b88ae58d888.24.05.png","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/2079","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=2079"}],"version-history":[{"count":2,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/2079\/revisions"}],"predecessor-version":[{"id":2354,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/2079\/revisions\/2354"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/media\/2082"}],"wp:attachment":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/media?parent=2079"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/categories?post=2079"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/tags?post=2079"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}