Pro_Unit

DelayAction

Dec 19th, 2018
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. using System.Collections;
  2. using UnityEngine;
  3. using UnityEngine.Events;
  4.  
  5. namespace GameCore
  6. {
  7.     public class DelayAction : MonoBehaviour
  8.     {
  9.         [SerializeField] float delay;
  10.         [SerializeField] UnityEvent action;
  11.  
  12.         public void Invoke()
  13.         {
  14.             StartCoroutine(IvokeDealayAction());
  15.         }
  16.         public void Invoke(float delayDuration, UnityAction _anction = null)
  17.         {
  18.             delay = delayDuration;
  19.  
  20.             if (_anction != null)
  21.                 action.AddListener(_anction);
  22.  
  23.             Invoke();
  24.         }
  25.  
  26.         IEnumerator IvokeDealayAction()
  27.         {
  28.             yield return new WaitForSeconds(delay);
  29.             action.Invoke();
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment