- Home /
Can I show a numeric variable from the slider on the GUI?
I tried to have this code added so I can have a slider, label, and the current value of the slider shown on screen. I get errors when I try to read the variable boatSpeed_Knots. How would I do this?
static var boatSpeed_Knots : double = 10.0;
function OnGUI () { GUI.Box (Rect (10, 20, 100, 25), "Knots"); boatSpeed_Knots = GUI.HorizontalSlider (Rect (10, 50, 150, 30), boatSpeed_Knots, 0.0, 40.0); GUI.Box (Rect (110, 20, 40, 25), boatSpeed_Knots); }
Answer by spinaljack · Aug 20, 2010 at 03:14 PM
You need to change boatSpeed_Knots into a string for the label to properly display it.
You can do this with either
"Speed = " + boatSpeed_Knots
or
boatSpeed_Knots.ToString()
Your answer
Follow this Question
Related Questions
Can I use the new GUI system with instantiated prefabs? 1 Answer
How to get a value from an array within another script. 1 Answer
How to calculate the width of the Rect, knowing current value and min and max values 0 Answers
How to make slider load variable on start 1 Answer
C# How To Save PlayerPrefs for Unity GUI 2 Answers