x


how do i create a slider after clicking a button?

what i want to do is create a slider in place of where a button was or next to the button. what i was trying to do was create the slider inside the button but when clicked would not create the slider. anyone know how to do this? any help would be appreciated. my code looks like this:

var SliderForMusic : float = 0.0;

function OnGUI () 
{
     if (GUI.Button (Rect (300, 200, 80, 40), "volumeControl"))
    {
        SliderForMusic = GUI.HorizontalSlider (Rect (25, 25, 100, 30), SliderForMusic, 0.0, 10.0);
    }

this was my understanding of it.

more ▼

asked Jan 07 '12 at 04:03 AM

cman19 gravatar image

cman19
16 2 4 7

Could you edit your question to include the snippet from your OnGUI function relevant to the problem? What you're trying to do is quite possible, so the problem is probably in your logic somewhere.

Jan 07 '12 at 04:05 AM syclamoth

can do give me a sec

Jan 07 '12 at 04:08 AM cman19
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Ok. The problem here is that the 'GUI.Button' function returns 'true' only on the exact frame that it gets pressed! The reason why your slider isn't appearing is because it is appearing for exactly one frame, and then disappearing again.

If you want the volumeControl button to disappear permanantly and get replaced by the 'SliderForMusic' slider, you could do this-

var buttonPressed = false;

function OnGUI()
{
    if(buttonPressed)
    {
        // draw the slider!
        // maybe also draw a button that sets 'buttonPressed' to false again
    } else {
        buttonPressed = GUI.Button (Rect (300, 200, 80, 40), "volumeControl");
    }
}
more ▼

answered Jan 07 '12 at 04:19 AM

syclamoth gravatar image

syclamoth
14.8k 7 15 80

thank you so much!

Jan 07 '12 at 04:21 AM cman19
(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:

x14

asked: Jan 07 '12 at 04:03 AM

Seen: 422 times

Last Updated: Jan 07 '12 at 04:21 AM