UnityUGUI之Button防止连续点击

欢迎加入Unity业内qq交流群:956187480

qq扫描二维码加群


public class MButton : Button
{
    public bool isClick;
    public float gapTime = 0;
    protected override void Awake()
    {
        onClick.AddListener(OnClick);
    }
    private void Update()
    {
        if (isClick)
        {
            gapTime += Time.deltaTime;
            if (gapTime > 2)
            {
                gapTime = 0;
                interactable = true;
                isClick = false;
            }
        }
    }

    private void OnClick()
    {
         isClick = true;
         interactable = false;   
    }
}
public class Test : MonoBehaviour {
    public MButton mButton;
    public MButton mButton1;
    private void Start()
    {
        mButton.onClick.AddListener(B);
        mButton1.onClick.AddListener(A);
    }

    private void B()
    {
        Debug.Log("b");
    }
    private void A()
    {
        Debug.Log("a");
    }
}

欢迎加入Unity业内qq交流群:956187480

qq扫描二维码加群

你可能感兴趣的:(UnityUGUI之Button防止连续点击)