Try doing
float myTimer = 70;
float TimeLeftInSeconds = 0;
float Minutes = 0;
float Seconds = 0;
string message = string.Empty;
function OnGUI(){
if(showGUI){
if(myTimer > 0){
TimeLeftInSeconds = myTimer -= Time.deltaTime;
if((TimeLeftInSeconds / 60) >= 1)
{
Minutes = Mathf.Floor((TimeLeftInSeconds / 60));
Seconds = TimeLeftInSeconds - (Minutes * 60);
message = "Minutes: " + Minutes + " Seconds: " + Seconds;
}else{
Seconds = TimeLeftInSeconds;
message = " Seconds: " + Seconds;
}
GUI.Box(new Rect(20,50,70,50), message);
}
if(myTimer <= 0){
GUI.Box(new Rect(20,20,100,50), "GAME OVER");
}
}
}
If you want to round up the seconds you can do Seconds = Mathf.Round(Seconds);
↧