有时候Button点下去不是要求立即反应的,而是先有个特别短的动画,再反应。
实现:
继承Button,然后重写一下OnPointerClick,利用协程来延迟。
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(); } }
来源:博客园
作者:朋丶Peng
链接:https://www.cnblogs.com/Peng18233754457/p/11444954.html