- Home /
Displaying the Value on a Horizontal Slider
I want to make a slider that has integer values between 0 and 90 inclusive. However, when i run this in my project, the word Angle along with the slider only appear. How can i display the value of the number between 0 and 90 right next to the slider?
function OnGUI () { mySlider = LabelSlider (Rect (10, 100, 100, 20), mySlider, 5.0, "Angle"); }
function LabelSlider (screenRect : Rect, sliderValue : float, sliderMaxValue : float, labelText : String) : float { GUI.Label (screenRect, labelText); screenRect.x += screenRect.width; // <- Push the Slider to the end of the Label sliderValue = GUI.HorizontalSlider (screenRect, sliderValue, 0.0, sliderMaxValue); return sliderValue; }
Answer by Joshua · May 30, 2011 at 03:36 PM
mySlider = LabelSlider (Rect (10, 100, 100, 20), mySlider, 5.0, "Angle");
The very last variable is the string you want to display. Replace it by "Angle"+mySlider to add the value of the slider to it.
mySlider = LabelSlider (Rect (10, 100, 100, 20), mySlider, 5.0, "Angle "+mySlider);
Your answer
![](https://koobas.hobune.stream/wayback/20220612092306im_/https://answers.unity.com/themes/thub/images/avi.jpg)