timer format

I have this timer code byt read 300, 299 etc when counting down. Is there a quick fix so it appears like so 3:00.

// the textfield to update the time to
private var textfield:GUIText;
 
// time variables
public var allowedTime:int = 300;
var currentTime = allowedTime;
  
function Awake()
{
    // retrieve the GUIText Component and set the text
    textfield = GetComponent(GUIText);
 
    UpdateTimerText();
 
    // start the timer ticking
    TimerTick();
}

function UpdateTimerText()
{
    // update the textfield
    textfield.text = currentTime.ToString();
}

function TimerTick()
{
    // while there are seconds left
    while(currentTime > 0)
    {
        // wait for 1 second
        yield WaitForSeconds(1);
 
        // reduce the time
        currentTime--;
 
        UpdateTimerText();
    }

    // game over
    //yield WaitForSeconds (10);
    //Application.LoadLevel ("Menu");
}

Thanks

This is somewhat confusing: if you want to show minutes and seconds, 300 seconds will result in 5:00!

If that’s what you’re looking for, you can do this:

function UpdateTimerText()
{
    var mins: int = currentTime / 60;
    var secs: int = currentTime % 60;
    // update the textfield
    textfield.text = mins + ":" + secs.ToString("D2");
}

Format “D2” converts to a string with 2 digits, padding with 0 at left.