x


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.

more ▼

asked Apr 25 '10 at 06:50 AM

CalledToGaming gravatar image

CalledToGaming
190 21 24 30

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

1 answer: sort voted first

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. ;)

more ▼

answered Apr 25 '10 at 01:04 PM

StephanK gravatar image

StephanK
6k 40 53 93

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.

Apr 25 '10 at 08:25 PM CalledToGaming
(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:

x5275
x3816
x3420
x109
x19

asked: Apr 25 '10 at 06:50 AM

Seen: 1611 times

Last Updated: Apr 25 '10 at 06:50 AM