Hi guys, I have a script that makes a countdown timer but I have a problem with it. Here’s my code:
Variable declaration:
public float Seconds;
public float Minutes;
In Update():
if(Seconds <= 0){
Seconds = 59;
if(Minutes >= 1){
Minutes --;
}
else{
Minutes = 0;
Seconds = 0;
}
}
else{
Seconds -= Time.deltaTime;
if(Mathf.Round (Seconds) <= 9){
timerText.text = timerText.text = "Mission time: " + Minutes.ToString () + ":0" + Seconds.ToString("f1");
}
else{
timerText.text = timerText.text = "Mission time: " + Minutes.ToString () + ":" + Seconds.ToString("f1");
}
}
Now, my problem with this code is the transitions. When it reaches 1:01 instead of going to 0:59 it goes from 1:00 to 0:59 to 0:58 really fast since it does the 1:00 for half a second then 0:59 the other half.
Also, when it reaches 0:10, instead of going directly to 0:09.xx it goes 0:9.xx for a few milliseconds.
Anyone can help me fix those two issues? Or is my code just to scrap and redo anew for what I want it to do?