I have a script that with the use of a GUIText object, displays the time left before the game is over. The time begins from 15 and reduces. If it reaches 0... game over. I have a question regarding this script:
because if I just use:
the timer goes from 15 to 14 in 0.5" instead of the expected 1". Why is that?
There's quite a few prettier ways to do what you need. What you're doing will not stick because timeLeftDisplayed will be immediately reset to what it should be on the next ongui refresh.
So immediately after you add 1 second it does what you're telling it to do:
If you want to stick to this way of counting down you should actually do
(and of course, don't make the variable private)
You should check this question out for a more correct way of counting down. Also remember that OnGui is a performance killer.
P.S: the first part of the answer was for an edited-out part of the question.