- Home /
Limiting digits in GUI displayed variables (or "snap to" GUI slider).
I have a metronome controlled by a GUI slider in my game. I have then displayed the value of the slider variable using GUI.Label. This works great, only the variable often has way to many decimals (i want it to have none). So obscure values come up for the value. Is there a way to preferably create a "snap to" GUI slider or just limit the no. of decimals to be displayed on the label? Any help will be greatly appreciated. Oh and I used variable.ToString() for displaying the variable in the GUI.
Answer by Mike 3 · Sep 07, 2010 at 09:22 PM
variable.ToString("F0");
will specify 0 decimal places or the string (F2 will be 2 decimal places, etc. in case you ever need to do that)
To answer your comment - if you want it to snap to every 5, in your specific case:
c#
variable = (((int)(variable - 3)) / 5) * 5;
js
var temp : int = (variable - 3);
variable = (temp / 5) * 5;
Should do it
Thankyou, i was wondering what the parentheses were for...
I just noticed that sometimes values such as 153 come up and then the next value down may be 148 (or alike). So 150 (for instance) as a metronome speed is unobtainable. Would there be anyway to as i mentioned create a "snap-to" GUI Slider. But this should be sufficient for now.
Thanks for the reply, but which variables do I swap the "variable" and "temp" with? Do I put it in "function Update () {}"?