README.md 1.21 KB
Newer Older
cann-alberto's avatar
cann-alberto committed
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Simulation Timer
An Lightweight Efficient Timer for Unity. Inspired by Photon Fusion TickTimer
## Usage/Examples

#### Simulation Timer

![](https://github.com/StinkySteak/com.stinkysteak.simulationtimer/blob/main/Gif/DefaultTimer.gif)

```csharp
private SimulationTimer _disableTimer;

private void Start()
{
    _disableTimer = SimulationTimer.CreateFromSeconds(_delay);
}

private void Update()
{
    if(_disableTimer.IsExpired())
    {
        _gameObject.SetActive(false);
        _disableTimer = SimulationTimer.None;
    }
}
```

#### Pauseable Simulation Timer

![](https://github.com/StinkySteak/com.stinkysteak.simulationtimer/blob/main/Gif/PauseableTimer.gif)

```csharp
private PauseableSimulationTimer _timer;

public PauseableSimulationTimer Timer => _timer;

private void Start()
{
    _timer = PauseableSimulationTimer.CreateFromSeconds(_delay);
}

public void TogglePause()
{
    if(!_timer.IsPaused)
    {
        _timer.Pause();
        return;
    }

    _timer.Resume();
}

private void Update()
{
    if(_timer.IsExpired())
    {
        _gameObject.SetActive(false);
        _timer = PauseableSimulationTimer.None;
    }
}
```
## Class Reference
`SimulationTimer`: Default Timer    
`PauseableTimer`: Pauseable Timer