.SetActive(true/false) not working properly

I am trying to make a menu and when you click on a menu,it needs to disapear and another one needs to get active.

I followed a youtube tutorial and i did exactly like there but it does not work.

I attached the MainMenu panel and OptionsPanel to currentstates.
And when i press any button i can see in the console the debug text.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MenuScript : MonoBehaviour {

    // enum states
    public enum MenuStates { Main, Options};
    public MenuStates currentstate;

    //panel objects
    public GameObject mainMenu;
    public GameObject optionsMenu;

    //when script starts
    void Awake()
    {
        //allways set first menu
        currentstate = MenuStates.Main;

    }

    void update()
    {
        //check current state
        switch (currentstate)
        {
            case MenuStates.Main:
                //set active gameobject for main menu
                mainMenu.SetActive(true);
                optionsMenu.SetActive(false);

                break;

            case MenuStates.Options:
                optionsMenu.SetActive(true);
                mainMenu.SetActive(false);

                break;
        }
    }

    public void OnStartGame()
    {
        Debug.Log("Start Button");

    }

    public void OnOptions()
    {
        Debug.Log("Options pressed");
        currentstate = MenuStates.Options;
    }

    public void OnWIndowedMode()
    {
        Debug.Log("On windowed pressed");
    }
    public void OnMainMenu()
    {
        Debug.Log("Back button pressed");
        currentstate = MenuStates.Main;

    }
}

Does this maybe have to do with your Update function being lowercase maybe? (it’s Update , not update) c# is case sensitive so I’m thinking that function won’t fire every frame (or at all in this case) if you have that typo.

Edit: I’ve confirmed that yes, “update” will never be called… you need to change it to Update (uppercase U). There may be other problems, but that is a huge one.

1 Like

When in doubt, use breakpoints, attach to process and play the game.

this would quickly point out to you that update was never called.

1 Like

Big mistake…
Thanks for the help!

Why not Activate / DeActivate these when they’re pressed instead of Update?
Events are literally the bread and butter when it comes to UI.

While calling deactivate and activate on certain objects during every frame might not impact the performance all that much, these things tend to add up.

That is what i did now.