x


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);
}
more ▼

asked Aug 20 '10 at 01:34 PM

ungoliath gravatar image

ungoliath
61 9 10 12

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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()
more ▼

answered Aug 20 '10 at 03:14 PM

spinaljack gravatar image

spinaljack
9.1k 18 31 91

Thanks for the help.

Aug 20 '10 at 04:38 PM ungoliath
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3698
x825
x123
x103
x4

asked: Aug 20 '10 at 01:34 PM

Seen: 1380 times

Last Updated: Aug 20 '10 at 03:12 PM