My float is always adding 1f to it even with no code telling it to
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!
Floats in text strings get rounded.
This question sounds like the same issue so the answer will probably work too.
Answer by Whiteleaf · Mar 19, 2016 at 01:41 AM
The answer is what Fredex8 said in the comments, thanks!
Your answer
Follow this Question
Related Questions
Timer float not evaluating correctly when I check if it's less than another number 3 Answers
How save playerprefs timer 0 Answers
Button still not appearing 0 Answers
"Object reference not set to the instance of an object" 0 Answers
Need thinking event, during time it takes to smtpserver.send 0 Answers