I’m making a timer, and beware since I’ve never done it before a lot of this code is taken from examples online. In the examples the people gave it seemed to work fine, but for me my ‘minutes’ float seems to add an extra 1 to it.
If you’re not catching on, here’s what I mean. My game starts out with 6 minutes, and it subtracts from there on out. In fact, the code works perfectly fine besides this problem. So when the game starts, I set my ui text to be equal to the timer which I’ve specified(works nicely). I print out the time in the console, and even though the time is right, 5:59, my text reads “6:59”. And here’s the weird thing–once it reaches “6:30” it adjusts itself to the correct time, “5:30”.
This is code for calculating the time. I don’t know why it’s adding 1 to the minutes–but hopefully you can help me out!
float guiTime = goalTime - Time.time;
//print (Time.timeSinceLevelLoad);
float mins = (guiTime / 60);
print (mins);
float sec = (guiTime % 60);
//timerText.text = mins.ToString("f0") + ":" + sec.ToString("f0");
timerText.text = string.Format("{00:00}:{00:00}", mins, sec);
some info: goalTime is set to Time.time + winningSeconds in Start(). (winning seconds is 360 seconds for 6 minutes). I’ve also tried using Time.timeSinceLevelLoad, as you can see and it does not seem to fix the issue.
I hope someone can help me with this, if you need any more information you can ask me! Thanks!