Skip to content

Commit bfe5a72

Browse files
Create Clock.cs
1 parent 5f5e3ed commit bfe5a72

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Clock.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
public class Clock
2+
{
3+
public Action OnTick;
4+
private System.Threading.Timer timer;
5+
private readonly int tickFrequency;
6+
public Clock(int tickFrequency)
7+
{
8+
timer = new System.Threading.Timer(Tick,null,tickFrequency,tickFrequency);
9+
this.tickFrequency = tickFrequency;
10+
}
11+
12+
private void Tick(object state)
13+
{
14+
OnTick?.Invoke();
15+
}
16+
17+
public void Awake()
18+
{
19+
timer.Change(tickFrequency, tickFrequency);
20+
}
21+
public void Pause()
22+
{
23+
timer.Change(Timeout.Infinite, tickFrequency);
24+
}
25+
26+
}

0 commit comments

Comments
 (0)