Hi,
I have an issue where I have a timer that countsdown between scenes, I’m using a date time to make sure that the timer holds the timer remaining between the scenes.
The problem that I have is that I have a 10 second timer but in the UI it displays as 00:00:10 and I’ll never go above a 2 digit number, so I only need the last 2 numbers to be visible, is there any way that I can achieve this with the current code that I have in place?
Here is the code for the countdown timer;
public static class GlobalCountDown
{
static DateTime TimeStarted;
static TimeSpan TotalTime;
public static void StartCountDown(TimeSpan totalTime)
{
TimeStarted = DateTime.UtcNow;
TotalTime = totalTime;
}
public static TimeSpan TimeLeft
{
get
{
var result = TotalTime - (DateTime.UtcNow - TimeStarted);
if (result.TotalSeconds <= 0)
return TimeSpan.Zero;
return result;
}
}
Here is where I initialize the countdown in the scene;
GlobalCountDown.StartCountDown (TimeSpan.FromSeconds (8))
And this is where I convert the timer into a string value that I’m able to display on the UI;
countdownTimer.text = GlobalCountDown.TimeLeft.ToString();
I think the change needs to occur where I set the timer ToString but am unsure on how to do this.
I’d appreciate any help or advice with this issue, thanks a lot!