- Home /
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?
Answer by Micha Lewtak 2 · Feb 07, 2010 at 03:07 PM
Nevermind, I had two instances of the script, so the sliders overlapped. Please delete this question.
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!
Your answer
Follow this Question
Related Questions
Crafting System - How to use a slider to show progress 0 Answers
How to make slider load variable on start 1 Answer
Expand mesh uniformly? 1 Answer
Use slider to modify alpha of a GUI Texture? 1 Answer
OnGUI sliders only accept float? C# 2 Answers