Quantcast
Channel: Answers for "mathf.round problem"
Viewing all articles
Browse latest Browse all 4

Answer by Bunny83

$
0
0
The problem is most likely the order of execution of your code. You first display the current "clicks" number, then you round it, then you add the autoClicks. Since your autoClicks is multiplied by deltaTime it will be a small value with a lot decimal points. You want to reverse those three lines: clicks += autoClicks * Time.deltaTime; clicks = mathf.round(clicks * 10f) / 10f; text.text = "" + clicks; You also want to put those lines at the end of your Update method. Any changes that are applied to "clicks" should happen before you round it. ***edit*** Furthermore there's another potential problem with that approach. Since you round the actual clicks counter you "distort" the actual value. At a high framerate it would be possible that your autoclicks addition might have no affect at all if it's too small and is going to be rounded away each frame. You should seperate the logic (the actual counting) from the display of the number. So only round it when displaying the number but leave the actual counter alone. clicks += autoClicks * Time.deltaTime; text.text = "" + (mathf.round(clicks * 10f) *0.1f); For other ways to output a formatted string see @Helliums answer.

Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>