summaryrefslogtreecommitdiff
path: root/GameCode/FlickerEvent.cs
blob: dd4096e961923a46ac7d1f21ce64f118b9eb906d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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;
		}
	}
}