- Home /
How to change how meany decimals are in a GUI sound slider
static var volumeSliderS = 1.0;
function OnGUI() {
volumeSliderS = GUI.HorizontalSlider (Rect(480, 130, 100, 30), volumeSliderS, 0.0, 1.0);
GUI.Label(Rect(480,105,200,30),"Music = "+volumeSliderS);
}
What I was wondering is how to change how meany decimals are in a GUI slider? When I play the game it is so long that it goes into my GUI.label and it is frustrating and don't know how to fix it.. My game is done its just I have been trying to find how to do this.
Answer by Eric5h5 · Jul 14, 2013 at 03:16 PM
Use standard .NET string formatting, such as volumeSliderS.ToString("f2")
for 2 decimal places.
Answer by KiraSensei · Jul 14, 2013 at 03:22 PM
If you want to round to the 3rd decimal, use :
var roundedSome = Mathf.Round(volumeSliderS * 1000) / 1000;
If you want to round to the 5th decimal, use :
var roundedSome = Mathf.Round(volumeSliderS * 100000) / 100000;
You need to change the number of 0 accordingly to the number of decimals.
Your answer
Follow this Question
Related Questions
Crafting System - How to use a slider to show progress 0 Answers
How to make slider load variable on start 1 Answer
Dynamic Resizing of tooltip to match content? 1 Answer
(GUI.Label) Line spacing issue with wordwrap 0 Answers
Making a text box appear after a certain gameObject is destroyed 0 Answers