forked from RevenantX/NetGameExample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameTimer.cs
More file actions
46 lines (38 loc) · 899 Bytes
/
Copy pathGameTimer.cs
File metadata and controls
46 lines (38 loc) · 899 Bytes
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
using System;
namespace Code.Shared
{
public struct GameTimer
{
private float _maxTime;
private float _time;
public bool IsTimeElapsed => _time >= _maxTime;
public float Time => _time;
public float MaxTime
{
get => _maxTime;
set => _maxTime = value;
}
public GameTimer(float maxTime)
{
_maxTime = maxTime;
_time = 0f;
}
public void Reset()
{
_time = 0f;
}
public void UpdateAsCooldown(float delta)
{
_time += delta;
}
public void Update(float delta, Action onUpdate)
{
_time += delta;
while (_time >= _maxTime)
{
_time -= _maxTime;
onUpdate();
}
}
}
}