I am using a float to calculate and display the time the player has left (in seconds) to finish the game.
In my game time sometimes goes faster, so the time left value needs to go big.
Here's my problem: I use the following code in Update:
Update () {
timeleft -= Time.deltaTime;
Debug.Log (timeleft);
counter.text = "Time Left = " +timeleft.ToString("F0");
}
At game start, the time left value is set to a really high number (32 million, about a year in seconds).
The rate at which the time drops varies in the game, so I am using a float with time.deltaTime.
Unity stores this big initial value as 3.2E+07. As soon as that happens, my counter.text doesn't work properly anymore, as that just waits until the next scientific notation value comes up. So it looks like the timer text is stuck, while in the back it is in fact still counting down. Hope I'm making sense here. For the avoidance of doubt: the counter display works fine for values below 1 million.
How do I fix this problem? How do I convert timeleft.ToString so that it displays the correct value?
As per the comments below, someone suggested to use a decimal instead. That won't work with deltaTime as that needs a float or I misunderstood where and how to use the decimal.
I tried to create a new int and use Mathf.RoundToInt on the float, but that doesnt work: the timer stays stuck at the larger value.