当前位置:网站首页>Unity prevents the BTN button from being clicked continuously

Unity prevents the BTN button from being clicked continuously

2022-06-22 14:28:00 Cangwolf King unity College

public class MyButton : MonoBehaviour

{

    public bool isClick;// Do you want to click

    public float tempTime = 0;// timer

    public Button Btn;// Button

    void Awake()

    {

       Btn.onClick.AddListener(OnClick);// Register button event

    }

    void Update()

    {

        if (isClick)// If clicked

        {

            tempTime+= Time.deltaTime;

            if (tempTime> 2)

            {

                tempTime= 0;

                Btn.enable = true;

                isClick = false;

            }

        }

    }

 

    private void OnClick()

    {

         isClick = true;

         Btn.enable= false;   

    }

}

 

原网站

版权声明
本文为[Cangwolf King unity College]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206221304023149.html