using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; using UnityEngine.Serialization; public class FuntionRepeat : MonoBehaviour { public float duration = 1f; public float tick = 0.1f; [Serializable] public class RepeatEvent : UnityEvent { } [FormerlySerializedAs("onRepeat")] [SerializeField] private RepeatEvent m_OnRepeat = new RepeatEvent(); public RepeatEvent OnRepeat { get { return m_OnRepeat; } set { m_OnRepeat = value; } } [Serializable] public class RepeatEndEvent : UnityEvent { } [FormerlySerializedAs("onRepeatEnd")] [SerializeField] private RepeatEndEvent m_OnRepeatEnd = new RepeatEndEvent(); public RepeatEndEvent OnRepeatEnd { get { return m_OnRepeatEnd; } set { m_OnRepeatEnd = value; } } public void Play() { CancelInvoke(); timeSum = 0; InvokeRepeating("Blink", 0, tick); } float timeSum = 0; void Blink() { OnRepeat.Invoke(); timeSum += tick; if (duration < timeSum) { CancelInvoke(); OnRepeatEnd.Invoke(); } } }