GUI Window Problem

Hi all,

i have worked with unity before six months. but am trying and working with GUI windows. it’s giving trouble to me about 2 hours. here is my code

using UnityEngine;
using System.Collections;

public class Menu : MonoBehaviour {

    public GUIStyle background = new GUIStyle();
    private bool menus = true;
    public Rect window1 = new Rect(3,3,Screen.width-3,Screen.height-3);

    void OnGUI()
    {
        GUI.Label(new Rect(0,0,Screen.width,Screen.height)," ",background); 

        if(menus)
        {
            if(GUI.Button(new Rect((Screen.width)/2-50,(Screen.height)/2-60,100,30),"Play Game"))
            {
                Application.LoadLevel(1);
            }

            else if(GUI.Button(new Rect((Screen.width)/2-50,(Screen.height)/2-20,100,30),"Settings"))
            {
                window1 = GUI.Window(1,window1,settingsWindow,"");
                menus = false;
            }

            else if(GUI.Button(new Rect((Screen.width)/2-50,(Screen.height)/2+20,100,30),"Credits"))
            {

            }
        }
    }

    void settingsWindow(int windowID)
    {
        GUI.Label(new Rect(50,50,100,30),"Volume");
    }
}

i have worked before in the same thing. here the problem is the new window is not opening. can any one say what am doing wrong?? Thank you in advance.

the window is opening, for a single frame because you have the window call inside the button block that will only run the moment the button is clicked.

you want to work with state variables here or a full state machine.

ya i need the window 'll open when i click on the button only… the window is opening when i give it outside of the if loop…any issues??

using UnityEngine;
using System.Collections;

public class Menu : MonoBehaviour {

    public GUIStyle background = new GUIStyle();
    private bool menus = true;
    public Rect window1 = new Rect(3,3,Screen.width-3,Screen.height-3);
[COLOR="red"]    private bool drawWindow = false;[/COLOR]

    void OnGUI()
    {
        GUI.Label(new Rect(0,0,Screen.width,Screen.height)," ",background); 

        if(menus)
        {
            if(GUI.Button(new Rect((Screen.width)/2-50,(Screen.height)/2-60,100,30),"Play Game"))
            {
                Application.LoadLevel(1);
            }

            else if(GUI.Button(new Rect((Screen.width)/2-50,(Screen.height)/2-20,100,30),"Settings"))
            {
[COLOR="red"]                drawWindow = !drawWindow;
[/COLOR]                menus = false;
            }

            else if(GUI.Button(new Rect((Screen.width)/2-50,(Screen.height)/2+20,100,30),"Credits"))
            {

            }
        }
[COLOR="red"]        if (drawWindow)
            window1 = GUI.Window(1,window1,settingsWindow,"");
[/COLOR]    }

    void settingsWindow(int windowID)
    {
        GUI.Label(new Rect(50,50,100,30),"Volume");
    }
}

@Seifer :
ya that’s correct… we need to set a boolean value…thank u for the answer…:slight_smile: