What I am trying to do is create an in-game menu GUI, and am having trouble closing some boxes. I have seen answers for similar problems, but not to this extent. After clicking a button and opening a box the player realizes this was the wrong choice and needs to click another button, kind of an “oops” thing.
So, if possible, is there a way to script closing an open GUI.Box and at the same time opening another?
My knowledge is very limited and I am learning as I trudge along, thank you for any assistance.
Script so far:
using UnityEngine;
using System.Collections;
public class NewGUIScript: MonoBehaviour
{
public GUISkin testSkin;
bool openMenu = false;
bool openPlayer = false;
bool openNew = false;
bool openSave = false;
bool openLoad = false;
bool openSettings = false;
bool openQuit = false;
bool openAbout = false;
bool boxDrawn = false;
private int width = 0;
void OnGUI()
{
GUI.skin = testSkin;
GUI.Box( new Rect( 1, 1, 70, 30), "");
if (GUI.Button( new Rect( 6, 6, 60, 20), "Menu"))
openMenu = !openMenu;
if (openMenu)
{
GUI.Box( new Rect (1, 29, width, 163), "");
if (boxDrawn)
{
if (GUI.Button( new Rect( 6, 35, 125, 20), "Player Setup"))
openPlayer = true;
if (GUI.Button( new Rect( 6, 57, 125, 20),"New Game"))
openNew = true;
if (GUI.Button( new Rect( 6, 79, 125, 20), "Save Game"))
openSave = true;
if (GUI.Button( new Rect( 6, 101, 125, 20), "Load Game"))
openLoad = true;
if (GUI.Button( new Rect( 6, 123, 125, 20), "Settings"))
openSettings = true;
if (GUI.Button( new Rect( 6, 145, 125, 20), "Quit Game"))
openQuit = true;
if (GUI.Button( new Rect( 6, 167, 125, 20), "About"))
openAbout = true;
}
}
if (openPlayer)
GUI.Box( new Rect( 133, 33, 160, 50), "Player Setup Box");
if (openNew)
GUI.Box( new Rect( 133, 55, 160, 50), "New Game Box");
if (openSave)
GUI.Box( new Rect( 133, 77, 160, 50), "Save Game Box");
if (openLoad)
GUI.Box( new Rect( 133, 99, 160, 50), "Load Game Box");
if (openSettings)
GUI.Box( new Rect( 133, 121, 160, 50), "Game Settings Box");
if (openQuit)
GUI.Box( new Rect( 133, 143, 160, 50), "Quit Game Box");
if (openAbout)
GUI.Box( new Rect( 133, 165, 160, 50), "About Game Box");
}
void Update ()
{
if (openMenu == true && width < 135 )
{
width += 9;
if(width == 135)
boxDrawn = true;
}
if (!openMenu)
{
width = 0;
boxDrawn = false;
}
}
}