timer problem

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;
	}
}

hi osvaldo19 ,

the problem i guess what is you’re not gradually increase time in update… i’m using this script in 2 of my games. its worked perfectly…try this.

 void Update()
    {
    guiTime = Time.deltaTime + guiTime;
    }
    void OnGUI()
    {
    minutes  =(int) guiTime / 60;
    seconds = (int) guiTime % 60;
    				
    textTime = string.Format ("{0:00}:{1:00}", minutes, seconds); 
    GUI.Label (new Rect (20,20,100,50), textTime,timerStyle); 
    }

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;