Search code examples
c#pongunity-game-engine

Creating an 'About' button then linking to Main Menu


Complete beginner here.

I've got a Main Menu (New Game, About, Quit), and another scene (Pong game). New Game is working (Application.Loadlevel → pong scene).

I'm trying to create a panel for the about menu, but I don't know how to enable/disable the menu.

I've got a pause menu that currently works, so I pretty much copied that script - the only difference is the pause menu gets triggered with 'ESC', but I'm trying to open the About menu with the mouse.

I'm trying to achieve the same thing by going back or (disabling) the about menu when I press the right arrow image (on the About page). This is in C# by the way.

Any advice?


Solution

  • Organize the menu in panels.

    Your Main Menu:

    public GameObject mainMenuPanel;
    

    Enable Panel

    mainMenuPanel.SetActive(true);
    

    Disable Panel

    mainMenuPanel.SetActive(false);
    

    If you have a huge menu and care about performance then you should get each individual UI component from the panel and enable/disable them. For example, the Button component:

    Button[] buttons = mainMenuPanel.GetComponentsInChildren<Button>();
    for (int i = 0; i < buttons.Length; i++)
    {
        //Enable
        buttons[i].enabled = true;
    
        //Disable
        buttons[i].enabled = false;
    }