slimecing

a fighting game featuring slimes and swords
Log | Files | Refs | README

OnStart.cs (862B)


      1 using Slimecing.Dependency;
      2 using UnityEngine;
      3 using UnityEngine.Events;
      4 
      5 public class OnStart : MonoBehaviour
      6 {
      7     [SerializeField] private float duration = 2f;
      8     [SerializeField] private int loops = 2;
      9     [SerializeField] private UnityEvent onTimerEnd = null;
     10 
     11     private Timer timer;
     12 
     13     private void Start()
     14     {
     15         Debug.Log("start");
     16         // Creates new instance of the namespace 'Timer'
     17         timer = new Timer(duration, loops);
     18 
     19         // Listen to events created by Timer
     20         timer.OnTimerEnd += ctx => HandleTimerEnd();
     21     }
     22 
     23     private void HandleTimerEnd()
     24     {
     25         // Calls event (alerts listeners)
     26         onTimerEnd.Invoke();
     27 
     28         // Any code that you wish to be executed whenever the Timer loops belongs here
     29         Debug.Log("loop finished");
     30     }
     31 
     32     private void Update() => timer.Tick(Time.deltaTime);
     33 }