Hi guys,
I set a count down timer, and it doesn’t what I want to count down. However, when the timeRemaining < 0, it does stop counting as 0:00, but it never been reset. Also, if I completed the game earlier, when I restart and reload the game, it still shows the time I left. I already tried to switch the Time.time to Time.deltaTime, and tried to use a reset function, but it seems doesn’t have any difference. I’m really new in unity, and I searched and tried the way as many as I can, but I still don’t know how to make it happen. Can anyone help me with that? Thanks!
Script as below:
var startTime: float;
var timeRemaining: float;
function start() {
startTime = 300.0;
}
function Update() {
Countdown();
}
function Countdown() {
if(timeRemaining > 0) {
timeRemaining = startTime - Time.time;
ShowTime();
}
else if(timeRemaining < 0) {
resetTimer();
}
}
function ShowTime() {
var minutes: int;
var seconds: int;
var timeString: String;
minutes = timeRemaining/60;
seconds = timeRemaining%60;
timeString = minutes.ToString() + ":" + seconds.ToString("D2");
guiText.text = timeString;
}
function resetTimer() {
startTime = 300.0;
}