Hello!
I am making a timer for my game, and I want it to follow the format of 00:00.
The code I am using means that 5m 4s, or similar, comes up as 5:4, and I want it to come up as 05:04.
If anyone knows how to fix this please let me know!
Thanks!
void Update () {
float t = Time.time - StartTime;
string minutes = ((int)t / 60).ToString();
string seconds = (t % 60).ToString("f0");
TimerText.text = minutes + ":" + seconds;
}
}
Timer.text = string.Format(“{0:0}:{1:00}s”,minutes,seconds);
should do it I think.
{0:0}
the first 0, before the :, is the first argument you pass after the string (ie: minutes). The second 0, after the :, is a formatting tool saying this can only be one integer into a string here. The first integer being the only integer you want, this works.
{1:00}
is similar, but gets the second argument and gets the first two integer chars.
You can also pass your arguments as an array if you have many.
void Update () {
float t = Time.time - StartTime;
float minutes = (t / 60);
float seconds = (t % 60);
Timer.text = string.Format("{0:00}:{1:00}",minutes,seconds);
}
Sorry, but it doesn’t work. It just adds milliseconds and an ‘S’ on the end, neither of which I want 
Thanks for trying though