using System; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace DefaultNamespace { public class TimerHelper : MonoBehaviour { private static TimerHelper _instance; public static TimerHelper Instance { get { if (_instance == null) { _instance = new GameObject("Timer").AddComponent(); } return _instance; } } //[EditorButton] public void SetTimerScale(float scale) { Time.timeScale = scale; } public void StartTimer(Action action, float time) { StartCoroutine(Timer(action, time)); } public void StartTimer(Action action, float time, T param) { StartCoroutine(Timer(action, time, param)); } public void StartTimer(List> actions, float time, T param) { StartCoroutine(Timer(actions, time, param)); } IEnumerator Timer(Action action, float time) { yield return new WaitForSeconds(time); action?.Invoke(); } IEnumerator Timer(Action action, float time, T param) { yield return new WaitForSeconds(time); action?.Invoke(param); } IEnumerator Timer(List> actions, float time, T param) { foreach (var action in actions) { yield return new WaitForSeconds(time); action?.Invoke(param); } } } }