- Home /
GUI Sliders in the same script. Question (Js.)
I'm working on an options menu for my game. For testing sake, (for my testers) I'm bringing in sliders to adjust things like player movement speed, jump speed, etc.
The problem I'm having is that when I have 2 sliders in the same script, only one of them reacts no matter which one I try to use. In this case, the "Player Speed" slider only works. When I click on the "Jump Height" slider, and try to drag it, it moves the "Player Speed" Slider Instead.
Any help would be appreciated, and I apologize for my recent uprising in questions. I've viewed, and reviewed the GUI Documentation resources and I'm still at a loss here. I'm finally making progress and I don't want to stop now!
var menu : boolean;
function Awake() { DontDestroyOnLoad(this); } function Start() { menu = false; }
function OnGUI() {if(menu == false) return; GUI.Box (Rect (10, 10,Screen.width - 20,Screen.height - 20), "Options");
//The problem is the two sliders below!!
//Player Speed Slider
GUI.Label (Rect (25,25,100,150),"Player Speed");
FPSMove.speed = GUI.HorizontalSlider (Rect(25,50,100,150), FPSMove.speed, 10.0,50.0);
//Jump Height Slider
GUI.Label (Rect (25,75,100,150),"JumpHeight");
FPSMove.jumpSpeed = GUI.HorizontalSlider (Rect(25,100,100,150), FPSMove.jumpSpeed, 10.0,20.0);
//The Problem is the two sliders above!!
//Resume Game
if(GUI.Button (Rect ( 300,Screen.height -75, 100,50),"Resume"))
{ menu = false; } //Return to Main Menu if(GUI.Button (Rect (400, Screen.height -75, 100,50),"Main Menu")) { Application.LoadLevel ("MainMenu"); } //Quit to Desktop if(GUI.Button(Rect (500, Screen.height - 75, 100,50),"Quit")) { Application.Quit(); } }
function Update() { //Toggle Options Menu On if(Input.GetButtonDown("O")) { menu = true; } //Exit Options Menu if(Input.GetButtonDown("Esc")) { menu = false; } }
Sorry for the mess that is this script. I'm trying to keep it as organized as I can, But trying to figure this scripting problem out is causing a little chaos.
Thanks again for any help.
Answer by StephanK · Apr 25, 2010 at 01:04 PM
You specified 150 as height for the slider. This makes the slider area so big, that it actually overlaps the area of the slider below. It seems that in this case Unity only processes the input for the element that was created first.
In short: adjust the height of the sliders to a sensible value (25 might work...). If you'd use GUILayout you would avoid this problem automagically. ;)
Thanks, That solved it. I appreciate the help. It's actually pretty often that I make mistakes like this. You'd think by now that I'd start catching these errors myself.
Your answer
Follow this Question
Related Questions
'MouseLook.sensitivityX' is inaccessible due to its protection level. 2 Answers
What is frame, How OnGuI is called every frame? 2 Answers
What can i use besides an event current 1 Answer
What Am I Doing Wrong? Variable Names 3 Answers
How do I add NPCs? 2 Answers