Countdown help......

Hi…

I´m doing a countdown for questions, 20 seconds to answer, if player answers correctly, the countdown must to stop… how can i make it?.. some ideas ?

I have this :

var countdownText : GUIText;

function Start(){
CountDown();}

function Update(){
if (Input.GetButtonDown("jump")){
    //Here some instruction to stop CountDown..
}
}

function CountDown(){
countdownText.text = "20";
yield WaitForSeconds(1);
countdownText.text = "19";
.
.
.
.
.
.
.... and so..
}

Do I must to do a While?, or maybe do I must to declare the CountDown in Update…

Thanks.

You may want to create a Stopwatch component ?

// Must the stopwatch stop functionning and trigger something when reaching the threshold ?
var hasThreshold : boolean = true;
var threshold : float;

// Boolean checked by Update function, whether the component increment the elapsedTime value.
private var stopwatchOn : boolean = false;
private var elapsedTime : float = 0.0;

function StartStopwatch() {
	stopWatchOn = true;
}

function StopStopwatch () {
	stopWatchOn = false;
}

function ResetStopwatch () {
	elapsedTime = 0.0;
}

function StopWatchThresholdReached () {
	StopStopwatch ();
	ResetStopwatch ();
}

function Update () {
	if (stopWatchOn) {
		elapsedTime += Time.deltaTime;
		if ( hasThreshold  threshold <= elapsedTime) {
			// Order the gameObject and all his children to execute the function StopWatchThresholdReached.
			BroadcastMessage ("StopWatchThresholdReached");
		}
	}
}

hmm, never figured out doing it with deltaTime… will try thanks!.