Simple Timer

Hi all,

I am using this code for a level timer.

var guiTime = Time.time - startTime;
		var minutes : float = guiTime / 60;
		var seconds : int = guiTime % 60;
		textTime = String.Format ("{0:00}:{1:00}", minutes, seconds);

Which I found in another old thread, which somewhat works, but t gives funny results.

For example, it counts up to the 1st minute fine, then goes up to 1:60, then back to 1:00 and then changes to 2 mins after an additional 30 seconds.

Does anyone have any ideas what is going wrong here?

Many thanks.

Maybe because minutes is float*?
Haven’t tested this tho:

var guiTime = Time.time - startTime;
var minutes : int = guiTime / 60;
var seconds : int = guiTime % 60;
 
textTime = String.Format ("{0:00}:{1:00}", minutes, seconds);

Try this code:

var guiTime = Time.time - startTime;
var minutes : int = guiTime / 60;
var seconds : int = guiTime % 60;
textTime = minutes.ToString() + ":" + (seconds < 10 ? "0" : "") + seconds.ToString();