TimerTrigger.cs (1130B)
1 using Slimecing.Dependency; 2 using UnityEngine; 3 using UnityEngine.Serialization; 4 5 namespace Slimecing.Triggers.TriggerLogic 6 { 7 [CreateAssetMenu(fileName = "TimerTrigger", menuName = "Triggers/SimpleTriggers/TimerTrigger")] 8 public class TimerTrigger : Trigger 9 { 10 [SerializeField] private float timerDuration = 0.1f; 11 [SerializeField] private int timerLoops = 0; 12 13 private Timer _timer; 14 15 public Timer timer 16 { 17 get => _timer; 18 set => _timer = value; 19 } 20 21 public float duration 22 { 23 get => timerDuration; 24 set => timerDuration = value; 25 } 26 27 public int loops 28 { 29 get => timerLoops; 30 set => timerLoops = value; 31 } 32 33 public override void EnableTrigger(GameObject target) 34 { 35 _timer = new Timer(duration, loops); 36 _timer.OnTimerEnd += ctx => TriggerPerformed(target); 37 } 38 39 private void TriggerPerformed(GameObject target) 40 { 41 OnTriggerStateChange(TriggerState.Performed); 42 } 43 } 44 }