- Home /
GUI.Label shows volume from a slider
why can't i do this
var hSliderValue2:float;
function Update(){AudioListener.volume=hSliderValue2;}
function OnGUI () {GUI.Label (Rect (1000, 475, 100, 30), hSliderValue2*10 .ToString());
hSliderValue2 = GUI.HorizontalSlider (Rect (1000, 500, 160, 30), hSliderValue2, 0, 1);}
I want to have a GUI.Label there will display 5 if the hSliderValue2 = 0.5
"I want to have a GUI.Label there will display 5 if the hSliderValue2 = 0.5"
is the problem that its displaying 5.32131239ish number, and you want it to display a solid 5 number?
Answer by illwunn · Aug 15, 2011 at 08:52 PM
try using this:
var hSliderValue2:float;
var hsliderFullNumber:float;
function OnGUI () {
hsliderFullNumber= Mathf.Round(hSliderValue2*10);
GUI.Box (Rect (10, 10, 100, 30), hsliderFullNumber.ToString());
hSliderValue2 = GUI.HorizontalSlider (Rect (10, 500, 160, 30), hSliderValue2, 0, 1);
}
DUDE, i'm almost crying now of happiness! IT WOR$$anonymous$$S 100%! ;D
3 answers? There is an EDIT button for revisions and new info.
Answer by illwunn · Aug 15, 2011 at 08:06 PM
well if thats the case then, you will just have to cast your output value into an int instead of a float to get a solid number.
try (int)hSliderValue2*10 .ToString(); or (hSliderValue2*10 as int) .ToString();
i usually use c# so im not too familiar with javascript syntax
did NOT work in the java script: BCE0044: expecting ), found 'hSliderValue2'.
Answer by illwunn · Aug 15, 2011 at 08:19 PM
var hSliderValue2:float;
function Update(){AudioListener.volume=hSliderValue2;}
function OnGUI () {GUI.Label (Rect (1000, 475, 100, 30), (int)hSliderValue2*10 .ToString());
hSliderValue2 = GUI.HorizontalSlider (Rect (1000, 500, 160, 30), hSliderValue2, 0, 1);}
var hSliderValue2:float;
function Update(){AudioListener.volume=hSliderValue2;}
function OnGUI () {GUI.Label (Rect (1000, 475, 100, 30), (hSliderValue2*10 as int).ToString());
hSliderValue2 = GUI.HorizontalSlider (Rect (1000, 500, 160, 30), hSliderValue2, 0, 1);}
Try either one of those, see how i replaced the content parameter in the GUI.label, try that and see if it outputs a solid number
2 erros: BCE0044: expecting ), found 'hSliderValue2'. BCE0043: Unexpected token: ).
at the first script. and the next one: BCE0006: 'int' is a value type. The 'as' operator can only be used with reference types.
Your answer
Follow this Question
Related Questions
Convert Text to float 3 Answers
Download a WWW int? Or convert? 1 Answer
convert string to int 0 Answers
c# convert int to string 2 Answers
Convert int to string 2 Answers