GUI Button and Window

Hello i’m trying to make gui button that shows a window but doesn’t seem to work.

private Rect windowRect = new Rect (200, 80, 120, 50);
private bool window1 = false;

	if(GUI.Button(new Rect(20,100,80,20), "Settings")){
		window1 = true;
		if (window1){
			windowRect = GUI.Window (0, windowRect, WindowFunction, "My Window");
		}
	}

	void WindowFunction (int windowID) {
}

Yea, I’d like to second what Sisso said. Definitely learn to debug.log. It can provide many eye-opening experiences. If you had debugged, you would have seen that your window does get opened, but doesn’t stay open, because that line of code only gets run in the instant you click your button. Move your “if(window1)” outside your “if(GUI.Button())” statement.

Also, I hope that’s not a 1:1 representation of your code, because those if statements are not getting run in any function. They must be placed in the OnGUI() function.