Hiding Buttons and Text?

In my game I’m trying to have it so if you die, text at the top will appear with the words “You have died.” and then at the bottom, there will be buttons to either restart, go to the main menu, or quit. The only problem I have with this is that I can’t get them to hide while I am not dead. I’ve been trying to figure this out, and your answer will be highly appreciated.

Here’s a really basic example of how to implement that. Of course you wouldn’t really want this in the Update function since there’s more efficient ways to handle it, but you get the idea.

public GameObject MainMenu; //Drag your main menu UI game object from the hierarchy to this area in the inspector. Same with the other game objects.
public GameObject Restart; //The restart button
public GameObject Quit; //The quit button
public GameObject GameOverText; //The game over text.

//Note that the .gameObject isn't necessary since they are all game objects, but if you want to define them as RectTransforms or something, you will need to add that in.

void Update(){
    
    
    if(health >= 1){
    MainMenu.gameObject.setActive(true);
    Restart.gameObject.setActive(true);
    Quit.gameObject.setActive(true);
    GameOverText.gameObject.setActive(false);
    }
    
    else{
    GameOverText.gameObject.setActive(true);
    MainMenu.gameObject.setActive(false);
    Restart.gameObject.setActive(false);
    Quit.gameObject.setActive(false);
    }
    
    
    
    
    }