Creating a Main Menu:

I'm having a problem with a script I'm trying to write. It's simple, but the answer's been evading me for several hours. I'm trying to create a main menu on a button click. Here's my script:

var customButton : GUIStyle;
var windowRect : Rect = Rect (20, 20, 120, 50);

function OnGUI () { 
    if (GUI.Button (Rect (1195, 6, 70, 20), "Menu", customButton)) {
        Menu();
        }
}

function WindowFunction (windowID : int) {
    // Draw any Controls inside the window here
}

function Menu () {
    windowRect = GUI.Window (0, windowRect, WindowFunction, "My Window");
}

Is there anything absurdly simple I'm missing? Anything absurdly complex? I'm trying to learn how to use the new GUI, but I'm afraid it's beyond my grasp if someone doesn't give me a hand. Thanks for any and all answers -

Elliot Bonneville

What your code does is show the menu only when the the button has been clicked, but only for that frame. You need to set a variable when the button is clicked, then check every frame if the variable has been set, and draw the menu if it has. Something like this should work (untested):

var customButton : GUIStyle;
var windowRect : Rect = Rect (20, 20, 120, 50);
var showMenu : System.bool = false;

function OnGUI () { 
    if (GUI.Button (Rect (1195, 6, 70, 20), "Menu", customButton)) {
        showMenu = true;
    }
    if (showMenu) {
        Menu();
    }
}

function WindowFunction (windowID : int) {
    // Draw any Controls inside the window here
}

function Menu () {
    windowRect = GUI.Window (0, windowRect, WindowFunction, "My Window");
}

I tried this and my script and this line,

var showMenu : System.bool = false;

wanted to be.

var showMenu : System.Boolean = false;

-kenm

try this it might help you out.

http://www.youtube.com/watch?v=YtBegzGYyjc&feature=channel