Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.63 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.Events;
  3.  
  4. public class TimerComponent : MonoBehaviour
  5. {
  6.     public float Timeout;
  7.     public bool Repeat;
  8.     public UnityEvent TimerElapsed;
  9.  
  10.     private float Timer { get; set; }
  11.  
  12.  
  13.     // Use this for initialization
  14.     public void Start()
  15.     {
  16.         Timer = 0;
  17.     }
  18.  
  19.     // Update is called once per frame
  20.     public void Update()
  21.     {
  22.         Timer += Time.deltaTime;
  23.  
  24.         if (Timer >= Timeout)
  25.         {
  26.             TimerElapsed.Invoke();
  27.  
  28.             if (Repeat)
  29.             {
  30.                 Timer = 0;
  31.             }
  32.             else
  33.             {
  34.                 this.enabled = false;
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement