- Home /
Ready Set Go timer
Hey everyone, I'm a little new to unity in terms of developing games, as well as a little rusty in my coding. Basically what I am trying to do is figure out a way to have text display on the screen as ques for the player. An example of this would be:
Start Timer
If Timer = 1 seconds then print = Ready
If Timer = 5 seconds then print = Go!
If Timer = 15 seconds then print = Game Over
I am also trying to figure out a way to modify the time (seconds) between the delays so that it can accomidate difficulty settings.
Any help of ideas on how I would start to accomplish this would be greatly appreciated!
Answer by dannyskim · Jan 17, 2012 at 07:07 PM
co-routines are your best friend when it comes to spacing out code in Unity based on time. Co-routines are so versatile, you could actually create your whole game / application strictly off of co-routines and not even use Update at all!
void Start()
{
StartCoroutine( readySetGoTimer( 2 ) );
}
private IEnumerator readySetGoTimer( float wait )
{
print("Ready");
yield return new WaitForSeconds(wait);
print("Set");
yield return new WaitForSeconds(wait);
print("GO!");
}
Just be careful if you want to do networking or save games as it may not be easy to restore coroutine state.
Your answer
Follow this Question
Related Questions
Visual timer? Like CUT THE ROPE 2 Answers
Rounding numbers of a timer 1 Answer
Time how long alive? 2 Answers
Why will this timer not count down? 1 Answer
Survival Timer 0 Answers