From 766cdff5ffa72b65d7f106658d1603f47739b2ba Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Fri, 27 Oct 2023 11:05:14 +0800 Subject: + init --- GameCode/FlickerEvent.cs | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 GameCode/FlickerEvent.cs (limited to 'GameCode/FlickerEvent.cs') 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; + } + } +} -- cgit v1.1-26-g67d0