¿ How can I do a countdown timer showed in GUI that restarts in each scene ?
Hi friends, I'm a videogame development student and i need a little help with something: I'm making a match game with a timer and a score that must be showed in GUI, the score is working perfectly but when the timer reaches zero, the code sends me to the menu, thats ok, but when I touch the restart button (that i've created) it loads the scene again but the timer has not been restarted and the menu is loaded again. Could you hel me with this ?
Here is the code (C#) void Awake() { startTime = 5; }
void OnGUI()
{
scoreTxt = scoreInt.ToString ();
GUI.Label (new Rect(10, 10, 100, 20), scoreTxt);
if (stopTimer == false)
{
float guiTime = Time.time - startTime;
Seconds = countSeconds - (guiTime);
}
if (Seconds < 0)
{
print ("The time is Over");
stopTimer = true;
Time.timeScale = 0;
Application.LoadLevel ("Menu");
}
roundedSeconds = Mathf.CeilToInt (Seconds);
txtSeconds = roundedSeconds % 60;
txtMinutes = roundedSeconds / 60;
string text = string.Format ("{0:00}:{1:00}", txtMinutes, txtSeconds);
GUI.Label (new Rect (10, 30, 100, 30), text);
}
Thanks in advance.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612091854im_/https://answers.unity.com/themes/thub/images/avi.jpg)