- Home /
Question by
Orloffyeah · Dec 31, 2012 at 09:49 PM ·
timerstartcountdown
Countdown Timer
Hi, I have been working on a countdown script and I was able to get it like this:
var Text : GUIText;
private var starttime = false;
function start()
{
starttime = true;
}
if (starttime == true)
{
StartCoroutine("CountDown");
}
function CountDown(){
yield WaitForSeconds(1);
Text.text = "3";
yield WaitForSeconds(1);
Text.text = "2";
yield WaitForSeconds(1);
Text.text = "1";
yield WaitForSeconds(1);
Text.text = "GO!";
}
But when I start it doesn't works, the GUIText isn't updating, could someone explain me why is this doesn't working?
Comment
Best Answer
Answer by Geo.Ego · Dec 31, 2012 at 10:21 PM
There are two things wrong here.
The
Start
function is not capitalized, so it won't run.Your
if (starttime == true)
statement is outside of the Start function (or any other function), so it won't run either.
So change your code to this:
var Text : GUIText;
private var starttime = false;
function Start()
{
starttime = true;
if (starttime == true)
{
StartCoroutine("CountDown");
}
}
function CountDown()
{
yield WaitForSeconds(1);
Text.text = "3";
yield WaitForSeconds(1);
Text.text = "2";
yield WaitForSeconds(1);
Text.text = "1";
yield WaitForSeconds(1);
Text.text = "GO!";
}
and it will work as expected.
Your answer
Follow this Question
Related Questions
Problem with countdown timer. 3 Answers
Countdown timer into text c# 1 Answer
How to restart a level with countdown? 4 Answers
Timer that stops at the end of the game 3 Answers