- Home /
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?
Answer by Berenger · May 18, 2012 at 04:58 PM
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
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 ins$$anonymous$$d of answer please ?
Answer by CornDog3241 · May 18, 2012 at 05:07 PM
So essentially I will have to create 4 panels or planes and name them accordingly, correct?
Answer by CornDog3241 · May 18, 2012 at 05:50 PM
Bare with me, I'm not a very strong programmer or scripter :/ haha
Your answer
