x


GUI Slider sets a value but the value appears to be reset by the end of OnGUI()

The following code always prints "1.0":

private var someVal=1.0;
function OnGUI() {
	someVal=GUI.HorizontalSlider(Rect(10,10,200,50),someVal,0.0,1.0);
}
function Update() {
	print(someVal);
}

The following code always prints the correct value which I define by sliding the slider:

private var someVal=1.0;
function OnGUI() {
	someVal=GUI.HorizontalSlider(Rect(10,10,200,50),someVal,0.0,1.0);
	print(someVal);
}

Additionally, I don't know if this is intentional or not, but when I slide the slider, I see a ghost version of the little knob still in its original position, which I guess is intentional, but when I release the mouse button it remains there.
Obviously I want my someVal to get adjusted with the slider. Does someone know what I'm doing wrong here?

more ▼

asked Feb 07 '10 at 02:49 PM

Micha Lewtak 2 gravatar image

Micha Lewtak 2
183 7 7 9

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

1 answer: sort voted first

Nevermind, I had two instances of the script, so the sliders overlapped. Please delete this question.

more ▼

answered Feb 07 '10 at 03:07 PM

Micha Lewtak 2 gravatar image

Micha Lewtak 2
183 7 7 9

I'd imagine this could potentially happen to another user, so it might be worth accepting your own answer and leaving it in the database in case others have this problem in future!

Feb 07 '10 at 03:22 PM duck ♦♦
(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:

x3672
x103

asked: Feb 07 '10 at 02:49 PM

Seen: 1312 times

Last Updated: Feb 07 '10 at 03:23 PM