Unity UGUI防止button按钮的连续点击

public class MyButton : MonoBehaviour
{
    public bool isClick;//是否点击
    public float tempTime = 0;//计时器
    public Button Btn;//按钮
    void Awake()
    {
       Btn.onClick.AddListener(OnClick);//注册按钮事件
    }
    void Update()
    {
        if (isClick)//如果被点击
        {
            tempTime+= Time.deltaTime;
            if (tempTime> 2)
            {
                tempTime= 0;
                Btn.enable = true;
                isClick = false;
            }
        }
    }
 
    private void OnClick()
    {
         isClick = true;
         Btn.enable= false;   
    }
}

你可能感兴趣的:(Unity UGUI防止button按钮的连续点击)