button activating another button

hello guys, I want to create a button which will create another button on a Gui system, but it seems to does not work. Is there any other way to do that?

code :

if(GUI.Button(Rect(335, 80, 50, 50), "Button1")) 
{

    if(GUI.Button(Rect(335, 140, 50, 50), "Button2"))
    {
        print("you clicked on the 2nd button"); 
    }    
}

thanks !

You probably need to store the state of the button in some variable and use this to display the second button.

var button1Clicked = false;
function OnGUI()
{
    if (GUI.Button(new Rect(335, 80, 50, 50), "Button1"))
    {
        button1Clicked = true;
    }

    if (button1Clicked)
    {
        if (GUI.Button(new Rect(335, 140, 50, 50), "Button2"))
        {
            print ("you clicked on the 2nd button");
        }
    }
}

I think (I can't remember the exact details) your code doesn't work because OnGUI gets called multiple times per frame (layout pass, input pass ...). During the layout pass the state of button presses will always be false and therefore your first if statement is always false.

Perhaps you want to use a toggle to show/hide the second button? Just add the button style to the toggle and it'll behave like a toggle button.

var toggle : boolean;
function OnGUI()
{
    toggle = GUI.Toggle(Rect(335, 80, 50, 50), toggle, "Button1", "button");

    if (toggle && GUI.Button(Rect(335, 140, 50, 50), "Button2"))
    {
        print("you clicked on the 2nd button"); 
    }    
}

Does the button have any other need? Or just display info... If just display info, check out GUI Tooltip:

http://unity3d.com/support/documentation/ScriptReference/GUI-tooltip.html

If the other, then you can check out this script, to go off of:

http://www.unifycommunity.com/wiki/index.php?title=PauseMenu

http://forum.unity3d.com/threads/49871-Open-a-new-gui-window-when-player-press-a-gui-button

That other link can help too.

Google around and you can find a lot of help =). Good luck!