需要一种在协程中使用按钮单击功能与 GetKeyDown 的方法

问题描述

这个动画脚本可以工作,但是,代替 WHILE LOOP 中的 Keycode 输入,我需要使用移动设备的 UI 按钮,我一直无法弄清楚。我找到了一个关于在它周围放置一个包装器以使方法可用于单击事件的答案,但不知道它应该如何在更新函数中工作。我花了很长时间才走到这一步,作为 unity 和 c# 的新手,所以如果您能提供详细的答案或建议,我可以恢复我的生活,如果可以,请提供帮助。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using SWS;

public class goat_question : MonoBehaviour
{
    private Animator anim;
    public GameObject player;
    public Text ResultText;
    public Text AnswerText;  
    public Text AnswerText2;
    public Button GoatButton;

  

    void Start()
    {
        anim = GetComponent<Animator>();
        Button btn = GoatButton.GetComponent<Button>();
        btn.onClick.AddListener(TaskOnClick);

    }

    void TaskOnClick()
    {
        Debug.Log("You have clicked the button!");
    }
   
    // Update is called once per frame
    void Update()

    {
        if (AnswerText.text.Equals(AnswerText2.text))

        {                                         

            StartCoroutine(GoatWalkPathCoroutine());        

        }

         IEnumerator GoatWalkPathCoroutine()
        {
            while (true)  
            {              

                    if (Input.GetKeyDown(KeyCode.K))  
                {
                    anim.Play("goat_hi_walk");
                    player.GetComponent<splineMove>().enabled = true;
                    yield return new WaitForSeconds(27);
                    anim.Play("goat_hi_licking");

                }
                yield return null;
            }

        }

    }

}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)