How can I disable UI on win screen and main menu screen

My lives and score UI is showing on the win screen and main menu. Only appears on the menu screen when I click the menu button on the win screen when I’ve played through a level. The UI only shows on the win screen after I have played through a level as well.

This is my current solution that works if you press the play again button on the win screen. Pressing the main menu button enables the UI again on the menu screen.

void Update()
{

    DisableUiOnWin();
    
}

public void DisableUiOnWin()
{
    if (SceneManager.GetSceneByName("You Win").isLoaded)
    { 
        Debug.Log("Disable UI!");
        uiCanvas.SetActive(false);
    }
    else
    {
        Debug.Log("Enable UI!");
        uiCanvas.SetActive(true);
    }
}

Hi Josh,

Thanks for sharing your solution. :slight_smile:

Regarding your question, you could opt for a slightly different approach: Set the UI game objects to false in Awake or when a new scene gets loaded, and set them on active depending on your rules when a new scene gets loaded.

There is an example in the API which you could use. It implements a method which gets called whenever a new scene got loaded:

https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager-sceneLoaded.html

Did this help?

Thanks.
But I had a problem implementing methods to be run in Awake on the gamesession script because I think it’s one persistent object and runs awake only once? Or is awake ran every level load even if its a persistent singleton script?

You are right. The Awake method gets called only once during the lifetime of an instance. For this reason, I suggested an alternative solution. Have you already taken a look at the link?

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms