-
Notifications
You must be signed in to change notification settings - Fork 0
/
Counter.cs
40 lines (33 loc) · 825 Bytes
/
Counter.cs
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
using System.Collections;
using UnityEngine;
namespace CoroutineSubstitute.Samples
{
public class Counter
{
public int Current { get; private set; }
public bool KeepRunning { get; set; } = true;
readonly ICoroutineRunner runner;
Coroutine coroutine;
public Counter (ICoroutineRunner runner)
{
this.runner = runner;
}
public void Start ()
{
coroutine = runner.StartCoroutine(CounterRoutine());
}
public void Stop ()
{
runner.StopCoroutine(coroutine);
coroutine = null;
}
IEnumerator CounterRoutine ()
{
while (KeepRunning)
{
Current++;
yield return null;
}
}
}
}