- Home /
Countdown Timer Help About putting 0's
Hello everyone, here is my countdown code :
var seconds =60; var a =0; var minutes = 14; var b = 0;
function Awake(){ a=1; }
function Update() {
GameObject.Find("Seconds").guiText.text =""+seconds; // says GUI TEXT called Seconds to put seconds on GameObject.Find("Minutes").guiText.text =""+minutes; // says GUI TEXT called Minutes to put minutes on
if(b==1) { CountdownMinutes(); }
if(a==1){ CountdownSeconds(); }
if(seconds == 0){ b = 1; } else { b=0; }
function CountdownSeconds(){ a=0; yield WaitForSeconds(1); seconds-=1; a=1; }
function CountdownMinutes() { b=0; minutes -=1; seconds = 60;
}
}
This is working quite well, but like this , there is 2 Gui text on the screen and starts like this :
14:59 like i wanted, but when the seconds get under 10, it's being like this:
14:5
but i want it to be like this 14:05 , i mean if it's under 10 i want it to put 0 near it,same thing for the minutes.
Any idea about doing this ?
Thanks.
Answer by Mike 3 · May 17, 2011 at 08:04 PM
You should be able to use seconds.ToString("00") to pad it to two numbers
in where ,
GameObject.Find("Seconds").guiText.text =""+seconds;
here ?
Your answer
Follow this Question
Related Questions
How to stop a Countdown Timer? 1 Answer
CountDown Timer Help (Seconds problem) 2 Answers
Turn seconds into minutes and seconds MM:SS 1 Answer
Format String Minutes:Seconds 3 Answers
Making a timer 1 Answer