Unity Button延遲功能

有時候Button點下去不是要求當即反應的,而是先有個特別短的動畫,再反應。ide

 

實現:動畫

繼承Button,而後重寫一下OnPointerClick,利用協程來延遲。spa

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; using UnityEngine.EventSystems; using UnityEngine.UI; public class MyButton : Button { [Header("執行onClick的延遲時間")] public float delayTime = 1f; public override void OnPointerClick(PointerEventData eventData) { StartCoroutine(Click()); } IEnumerator Click() { Debug.Log("動畫..."); yield return new WaitForSecondsRealtime(delayTime); onClick.Invoke(); } }
相關文章
相關標籤/搜索