Managing GUI Windows

Hello

I have a GUI menu with many buttons, when clicked the button sets a bool value and opens a new window, at the same time closing the previous window open. Currently I’m setting a lot of bools true or false on each click. I thought I might be able to do something like this:

public void MenuManager(bool openWindow)
{
    window1 = false; // Stop showing the window
    window2 = false;
    window3 = false;
   
    openWindow = true; // Show only this window , Could be any of the above windows
}

The way I am going about it is to set all window bools to false, then set the window bool passed in to the method true to display the window. This results in all of the windows staying closed. Not as I expected, anyone have an idea as to why this is happening? or a suitable alternative.

Thanks

I believe your function isn’t working because you are passing openWindow as a value, so this won’t actually change the original variable, any changes you make to openWindow dont affect the variable you passed to MenuManager.

public void MenuManager(ref bool openWindow)
{
    window1 = false; // Stop showing the window
    window2 = false;
    window3 = false;

    openWindow = true; // Show only this window , Could be any of the above windows
}

might make it work. Instead of using bools, i’d use a enumerator

enum Windows {window1, window2, window3};
Windows currentWindow = Windows.window1;

public void OpenWindow(Windows w)
{
switch(w)
{
case Windows.window1:
//open window 1 close other windows
case Windows.window2:
//open window 2 close other windows
case Windows.window3:
//openWindow 3 close other windows
}
}

another example of enumerations

void OnGUI()
	{
		if(GUI.Button(new Rect(0,0, 10, 10), "Open Window 1"))
		{
			currentWindow = Windows.Window1;
			OpenWindow(currentWindow);
		}
		switch(currentWindow)
		{
		case Windows.NoWindows:
			//display gui for no windows
			break;
		case Windows.Window1:
			//display gui for Window1
			if(GUI.Button(new Rect(0,0,10,10), "Close Window Button"))
			{
				currentState = Windows.NoWindows;
			}
			break;
			//........
		}
	}