GUI.Window not showing up.

Hello all,

I am dumbfounded on why my GUI Window is not opening. I have checked it 100 times and it just will not work, I am sure its something simple I just cant find what it is.

When I click on a button, GUILayout.window is supposed to open:

	void OnGUI()
	{
//Set Player Stats Button
		if(GUI.Button(new Rect(Screen.width / 2 + 200, Screen.height / 2  + 200, playerStatsButtonWidth, playerStatsButtonHeight), "Set Player Stats"))
		{
			Debug.Log("clicked");
			joinTeamLeftIndent = Screen.width / 2 - joinTeamWindowWidth / 2;			
			joinTeamTopIndent = Screen.height / 2 - joinTeamWindowHeight / 2;			
			joinTeamRect = new Rect(joinTeamLeftIndent, joinTeamTopIndent,joinTeamWindowWidth, joinTeamWindowHeight);			
			joinTeamRect = GUILayout.Window(1, joinTeamRect, MyWindowName, joinTeamWindowTitle);
		}

		
	}

Notice it calls the function: MyWindowName (just a random name I chose since I couldnt get this working). Here is that function listed in the same script.

	void MyWindowName(int WindowID)
	{
		//Run the Stats function from the PlayerStats script.
		Debug.Log ("is this running?");
		//GameObject gameManager = GameObject.Find("MultiplayerManager");		
		//PlayerStats statScript = gameManager.GetComponent<PlayerStats>();
		//
		//statScript.Stats();
	}

Right now I cant even get that debug.log(“is this running”) to print out. When I click on the button, the debug.log (“clicked”) does play like it should. But not the other one. What in world is happening any ideas?

Great you figured it out yourself ;) However you might want to change the questions title into something more related to the question / problem or this question / answer doesn't help much.

Updated :)

1 Answer

1

Solved. Apparently you cant put a window inside of a GUILayout.Button. I changed it to this and it works now:

		if(GUI.Button(new Rect(Screen.width / 2 + 200, Screen.height / 2  + 200, playerStatsButtonWidth, playerStatsButtonHeight), "Set Player Stats"))
		{
			Debug.Log("clicked");
			iClicked = true;
			/*joinTeamLeftIndent = Screen.width / 2 - joinTeamWindowWidth / 2;			
			joinTeamTopIndent = Screen.height / 2 - joinTeamWindowHeight / 2;			
			joinTeamRect = new Rect(joinTeamLeftIndent, joinTeamTopIndent,joinTeamWindowWidth, joinTeamWindowHeight);			
			joinTeamRect = GUILayout.Window(29, joinTeamRect, MyWindowName, joinTeamWindowTitle);
		*/
		}
		
		if(iClicked)
		{
			joinTeamLeftIndent = Screen.width / 2 - joinTeamWindowWidth / 2;			
			joinTeamTopIndent = Screen.height / 2 - joinTeamWindowHeight / 2;			
			joinTeamRect = new Rect(joinTeamLeftIndent, joinTeamTopIndent,joinTeamWindowWidth, joinTeamWindowHeight);			
			joinTeamRect = GUILayout.Window(29, joinTeamRect, MyWindowName, joinTeamWindowTitle);
		}

Just to be clear, GUI.Button returns true for the one frame that it was clicked. So putting GUILayout.Window inside GUI.Button makes the window appear for one frame. OnGUI is immediate mode.

Ah good to know the why behind it. Thanks!