- Home /
Timer stopped on gameover in car racing game unity
i'm very beginner to unity. i want to stop the car when counting time reaches to 0s. here is my code #pragma strict private var startTime : float; var textTime : String; //First define two variables. One private and one public variable. Set the first variable to be a float. //Use for textTime a string. function Start() { startTime = 60.0f; } function OnGUI () { var guiTime = startTime - Time.time ;
//The gui-Time is the difference between the actual time and the start time. var minutes : int = guiTime / 60; //Divide the guiTime by sixty to get the minutes. var seconds : int = guiTime % 60;//Use the euclidean division for the seconds. var fraction : int = (guiTime * 100) % 100;
textTime = String.Format ("{0:00}:{1:00}:{2:00}", minutes, seconds, fraction); //text.Time is the time that will be displayed. GetComponent(GUIText).text = textTime;
}
Your answer
Follow this Question
Related Questions
CountDown Timer Help (Seconds problem) 2 Answers
Start countdown timer on a button press 2 Answers
CountDown Camera problem 0 Answers
Wait in Coroutine doesn't work 0 Answers
countdown timer 0 Answers