- Home /
Game Time with variable count speed
Hi,
I was wondering how to make a game time counter that has varying counting speed. What I mean by that is:
Normal Counting:
[1] (1 second wait), [2] (1 second wait), [3] (1 second wait), [4] (4 second wait)
Fast Counting:
[1] (.5 second wait), [2] (.5 second wait), [3] (.5 second wait)
Even faster counting:
[1] (.1 second wait), [2] (.1 second wait), [3] (.1 second wait)
The (x second wait) being the real time and the integer in the bracket[] before that being in game time.
How would I go about doing this? It seems like Update() and FixedUpdate() both update multiple times before actually displaying the values changed within the function (or am I mistaken?) so with my current knowledge i have no idea how to make it count reliably... Thanks!
Answer by AlwaysSunny · Feb 03, 2015 at 10:05 PM
Easy enough, if I understand. The sample below uses a Coroutine. An invaluable tool once you understand them.
int ticks;
float delay = 0.5f;
void Start() { StartCoroutine(Timer()); }
IEnumerator Timer() {
yield return new WaitForSeconds(delay);
ticks++;
StartCoroutine(Timer());
}
Ah! I see. Coroutine was what I was looking for. Thanks a bunch! Works perfectly.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Make a variable start at 10 and count down until 0 3 Answers
Distribute terrain in zones 3 Answers
Calling a variable in C#? 1 Answer
Variable is always false... 1 Answer