summaryrefslogtreecommitdiff
path: root/GameCode/FlickerEvent.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2023-10-27 11:05:14 +0800
committerchai <215380520@qq.com>2023-10-27 11:05:14 +0800
commit766cdff5ffa72b65d7f106658d1603f47739b2ba (patch)
tree34d7799a94dfa9be182825577583c0fa6dc935f7 /GameCode/FlickerEvent.cs
+ init
Diffstat (limited to 'GameCode/FlickerEvent.cs')
-rw-r--r--GameCode/FlickerEvent.cs48
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;
+ }
+ }
+}