Unity初学者--轻点点击一次以上就会发生火灾

问题描述 投票:1回答:2

我有一个四边形对象,其中有一个png图形作为子对象。

这个区域是点击区域。

我给这个对象附加了一个脚本,里面有代码。

// Update is called once per frame
    void FixedUpdate () {

        bool tapped = Input.GetButton("Fire1");

        if (tapped){

            Debug.Log ("diram");

        }

    }

Up]

. Those methods return true respectively in the first frame the button is pressed or release.

Consider also read input events inside
android ios unity3d
2个回答
1
投票

Input.GetButton If you want to delay the shot you could also add a timer and another variable:

Hope that helped!Update我在这里做错了什么?我不希望一个函数在点击或单击时被调用两次。FixedUpdate


0
投票

当你按住按钮时返回true。你应该使用

    public float delay; //change this in the Inspector
    public bool canshoot = true;

    private void Start()
    { 
      bool input = Input.GetButton("Fire 1");
      if(input && canshoot){
         canshoot=false;
         Shoot() // your shooting function)
         StartCoroutine(Reset(delay));
        }
    }


   IEnumerator Reset(float time){
    yield return new WaitForSecondsRealTime(time);
    canshoot = true;
    }

Input.GetButton[Down

© www.soinside.com 2019 - 2024. All rights reserved.