I have this timer script that I thought was working but then I noticed that it increases by 1 minute every 30 seconds. Can anyone help me spot the error?
private var startTime;
private var finalTime:float;
public var gameEnded:boolean;
var textTime : String;
var customSkin:GUISkin;
function Awake(){
startTime =Time.time;
}
function OnGUI(){
var guiTime;
if(!gameEnded)
guiTime = Time.time - startTime;
else
guiTime = finalTime;
var minutes : int = guiTime / 60;
var seconds : int = guiTime % 60;
var fraction : int = (guiTime * 100) % 100;
if(!gameEnded)
{
text = String.Format ("{0:00}:{1:00}:{2:00}", minutes, seconds, fraction);
this.guiText.text = text;
guiText.material.color = Color.black;
}
}
Thanks but I eventually found the answer that allowed me to keep the fractions. Here’s what needed to change from my original script, just in case you want a timer with fractions:
var minutes : int = Mathf.Floor(guiTime/59);
var seconds : int = Mathf.Floor (guiTime % 59);
var fraction : int = (guiTime * 100) % 100;