Android 使用EventTrigger将代码应用于游戏对象

Android 使用EventTrigger将代码应用于游戏对象,android,touch,Android,Touch,我有一个按钮,我想表示“攻击”。我在为android编程 基本上我想在点击攻击按钮后运行这个脚本。我没有使用F键来阻止代码快速重复,而是试图找出如何为“if button is touch&!isAttacking”运行if语句,然后进入该方法 if (Input.GetKeyDown(KeyCode.F) && !isAttacking) { isAttacking = true; attackTimer = attackCD;

我有一个按钮,我想表示“攻击”。我在为android编程

基本上我想在点击攻击按钮后运行这个脚本。我没有使用F键来阻止代码快速重复,而是试图找出如何为“if button is touch&!isAttacking”运行if语句,然后进入该方法

if (Input.GetKeyDown(KeyCode.F) && !isAttacking)
     {
         isAttacking = true;
         attackTimer = attackCD;
         Debug.Log("F Pressed");

         attackTrigger.enabled = true;
     }

     if (isAttacking)
     {
         if (attackTimer > 0)
         {
             attackTimer -= Time.deltaTime;
         }
         else
         {
             isAttacking = false;
             attackTrigger.enabled = false;
         }
     }

我用的是Unity 5

将onClickListener/onTouchListener设置为按钮,并在该方法中进行检查!我正在使用Unity 5,但问题是在if语句中它正在等待触发器。现在是关键时刻。如果我要删除GetKeyDown,代码会循环,因为它会说“如果角色没有攻击,请将isAttacking设置为true”。我需要用另一个输入替换GetKeyDown,即touch。我不明白:为什么不从gameloop中删除第一个If并将其添加到侦听器?然后,您可以删除getKeyDown。您能给我一个这样做的示例吗?下面是关于unity按钮的教程:。但我会寻找一个代码示例