I have a timer but it displays the numbers after the decimals while I only want it to display whole numbers. Any suggestions?
(comments are locked)
|
|
If you just want the ceiling:
If you just want to drop the decimal and get the floor: Simple and effective. I'll take it!
Nov 02 '10 at 08:54 PM
Persona
(comments are locked)
|
|
If you want to truncate the time, you could have Unity do the timing for you and then just print that.
This will improve performance as well because you are not calling the method every frame. Only once per second. So, if performance matters, this is the fastest method. Oooh, very nice :)
Nov 02 '10 at 08:45 PM
Atnas1010
(comments are locked)
|
This should work.
(comments are locked)
|
|
You could try Mathf.Round() or something similar, or just convert the float to an int it will drop the fraction.
Unity JS has dynamic typecasting, so it should just work. I didn't test it, though. Cheers == Converting the float to an int would make the counting stop, since Time.deltaTime is a float
Nov 02 '10 at 08:06 PM
Atnas1010
I believe equalsequals was referring to converting to an int inside the guiText.text, not at your declaration - this would not stop the counting.
Nov 02 '10 at 08:10 PM
skovacs1
How would one do that?
Nov 02 '10 at 08:13 PM
Atnas1010
edited my post.
Nov 02 '10 at 08:23 PM
equalsequals
(comments are locked)
|
|
You can use an integer and subtract one every second, instead of using a float in Update. See my answer here: http://answers.unity3d.com/questions/12992/count-down-timer-per-second I believe that is what I did. ;)
Nov 02 '10 at 10:27 PM
Peter G
@Peter G: Well, so it is...maybe I should read the other answers more thoroughly next time.... Pity the accepted answers are the less efficient ones. ;)
Nov 02 '10 at 10:46 PM
Eric5h5
Hey, I go for simple enough for me to understand. Besides, I openly admit, I'm too incompetent right now to know the difference in the CPU cycle.
Nov 03 '10 at 02:12 AM
Persona
(comments are locked)
|
