Convert second to HH:MM:SS and insert into GuiText

i need help in this problem. i try to make a timer in HH:MM:SS.
var Counter: int = 0;
var minutes : int = 0;
var hours : int = 0;
var seconds : int = 0;

function CalculateCounter()
{
Counter++;
while(Counter >= 3600)
{
hours++;
Counter -= 3600;
}
while(Counter >= 60)
{
minutes++;
Counter -= 60;
}
seconds=counter;

CounterTimer.guiText.text = “”+hours+“:”+minutes+“:”+seconds;

}

The problem is the counter only count for second… the minutes and hours didnt come out.

…(Although there are all kinds of weird things going on in your code, and you aren’t going to get real time unless you use something from the Time class like Time.deltaTime) … for the conversion of seconds to hours minutes seconds why not do:

hours = counter / 3600;
minutes = (counter % 3600) / 60;
seconds = (counter % 3600 ) % 60;
3 Likes