i want to open another gui if the player clicks a gui button.
so … if the player clicks on my third button it should open/enable a new gui window
this is my code so far
function OnGUI () {
// Make a background box
GUI.Box (Rect (10,10,100,120), “Menu”);
// Button 1: Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
if (GUI.Button (Rect (20,40,80,20), “Restart”)) {
Application.LoadLevel (“Level 1”);
}
// Button 2: Make the second button.
if (GUI.Button (Rect (20,70,80,20), “Main Menu”)) {
Application.LoadLevel (“Level 2”);
}
//Button 3: make third button here should be the button to make a new gui???
if (GUI.Button (Rect (20,100,80,20), “Info”)) {
}
}
should a make a new script with the new gui i want to activatie, and activatie/enable it if player clicks on button 3 somehow?
That would be one way of doing it - you could also have a bool in your script. try something like:
var showMoreGui = false;
function OnGUI () {
if (GUI.Button (Rect (10,10,100,20), "Show More"))
showMoreGui = true;
if (showMoreGui) {
GUI.Button (Rect (10, 40,100,20), "Hello there");
if (GUI.Button (Rect (10, 70,100,20), "Close"))
showMoreGui = false;
}
}
To seperate it out a bit, you could do:
var showMoreGui = false;
function OnGUI () {
if (GUI.Button (Rect (10,10,100,20), "Show More"))
showMoreGui = true;
if (showMoreGui)
ExtraGUI ();
}
function ExtraGUI () {
GUI.Button (Rect (10, 40,100,20), "Hello there");
if (GUI.Button (Rect (10, 70,100,20), "Close"))
showMoreGui = false;
}
Whether you want to split out this more GUI or do it like this generally depends on the complexity. I usually start with just having it inline, then move it to a separate function before completely splitting it out.
Just felt like adding another thanks,
cause I’ve been looking for a solution to a real head scratchy issue I’ve been having,
tried your ‘simple as hell’ solution earlier too,
but for the life of me didn’t work (I probably had the ‘True’ start with capital!),
so been search all night only to find this, and feel the 'do-oh moment, so I’m much obliged.