I have a button that draws a gui box, and a button that shuts the box, however after I shut the box, I can no longer open it again from the open box button.
Any ideas?
using UnityEngine;
using System.Collections;
public class Gui : MonoBehaviour {
bool boxcheck1 = false;
bool boxcheck2 = false;
bool boxcheck3 = false;
bool boxcheck4 = false;
bool shutboxcheck1 = false;
//Campaign box
void OnGUI() {
if (GUI.Button(new Rect(250, 700, 90, 20), "Campaign")){
boxcheck1 = true;
}
if (boxcheck1 == true) {
boxcheck2 = false;
boxcheck3 = false;
boxcheck4 = false;
GUI.Box(new Rect(10, 10, 1008, 680), "");
if (GUI.Button(new Rect(870, 650, 110, 20), "Close window")){
shutboxcheck1 = true;
}
if (shutboxcheck1 == true) {
boxcheck1 = false;
boxcheck2 = false;
boxcheck3 = false;
boxcheck4 = false;
}
}
There needs to be a way the booleans can be set to true is my guess. Try that
The problem is that shutboxcheck1 will still be true when you click the campaign button - instantly closing the window again. Try this:
//Campaign box
void OnGUI()
{
if (GUI.Button(new Rect(250, 700, 90, 20), "Campaign"))
{
boxcheck1 = true;
}
if (boxcheck1 == true)
{
boxcheck2 = false;
boxcheck3 = false;
boxcheck4 = false;
GUI.Box(new Rect(10, 10, 1008, 680), "");
if (GUI.Button(new Rect(870, 650, 110, 20), "Close window"))
{
shutboxcheck1 = true;
}
if (shutboxcheck1 == true)
{
boxcheck1 = false;
boxcheck2 = false;
boxcheck3 = false;
boxcheck4 = false;
shutboxcheck1 = false; // NEW
}
}
}