diff options
Diffstat (limited to 'GameCode/FlickerEvent.cs')
-rw-r--r-- | GameCode/FlickerEvent.cs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/GameCode/FlickerEvent.cs b/GameCode/FlickerEvent.cs new file mode 100644 index 0000000..dd4096e --- /dev/null +++ b/GameCode/FlickerEvent.cs @@ -0,0 +1,48 @@ +using UnityEngine; +using UnityEngine.Events; + +public class FlickerEvent : MonoBehaviour +{ + public UnityEvent onEvent; + + public UnityEvent offEvent; + + public float interval; + + private float c; + + public bool isOn; + + private bool flickedOn; + + private void Start() + { + } + + private void Update() + { + c += TimeHandler.deltaTime; + if (isOn) + { + if (c > interval) + { + flickedOn = !flickedOn; + if (flickedOn) + { + onEvent.Invoke(); + } + else + { + offEvent.Invoke(); + } + c = 0f; + } + } + else if (flickedOn && c > interval) + { + c = 0f; + offEvent.Invoke(); + flickedOn = false; + } + } +} |