x


Displaying a panel on GUI click

I'm in the process of making a Serious Game for a class I have, and I'm trying to display a box or a panel when I click one of the 4 GUI buttons. What would be the easiest way to make a panel be displayed when a certain button is clicked? Also, could I have 4 different panels? For example, if I click one button, Panel A shows up. If I click another button, Panel B shows up. Is that possible?

more ▼

asked May 18 '12 at 04:37 PM

CornDog3241 gravatar image

CornDog3241
0 1 2 4

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

3 answers: sort voted first

It's possible and there is many ways to do it. You could have everything in one script and display the correct panel depending on an enum

public enum PanelType{ Apple, Banana, Orange, None }

// class, OnGUI ans stuff ...

if( GUI.Button(...) ) type = PanelType.Apple;

//...

if( type == PanelType.Apple ) DisplayApplePanel();
else ...

Or you could use a separate script for the pannels and enable the one you need

public MyPannel one, two, three, four;

// ...

if( GUI.Button(...) ) // Disable last one and enable new one
more ▼

answered May 18 '12 at 04:58 PM

Berenger gravatar image

Berenger
11k 12 19 53

UnityGUI (this is the name of what's happening in OnGUI()) takes care of how it is displayed. You need to attach a script to a gameobject that implement the function OnGUI. Inside, you need can call GUI.Label, Button, Box etc. That gameObject doesn't need a mesh or anything else.

Could use comments instead of answer please ?

May 18 '12 at 07:43 PM Berenger
(comments are locked)
10|3000 characters needed characters left

So essentially I will have to create 4 panels or planes and name them accordingly, correct?

more ▼

answered May 18 '12 at 05:07 PM

CornDog3241 gravatar image

CornDog3241
0 1 2 4

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

Bare with me, I'm not a very strong programmer or scripter :/ haha

more ▼

answered May 18 '12 at 05:50 PM

CornDog3241 gravatar image

CornDog3241
0 1 2 4

(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:

x3685
x109
x7

asked: May 18 '12 at 04:37 PM

Seen: 586 times

Last Updated: May 18 '12 at 07:43 PM