What's the best way to hide/show a panel?

Simple question, but I’m struggling to find instruction on this. I have text in a panel (in a canvas), and I need to show it when dialogue is happening. What’s the best way to show and then hide the panel?

I don’t want to hide the entire canvas because I have other UI elements on screen (unless I should be using 2 separate canvas’ for those?)

yes. it possible.

video - hide and show the panel

I think this tutorial can help you solve the problem.

This code is working for unity 5. Tested.

This code is to hide the panel.

    Panel.gameObject.SetActive (false);

This is to show the panel.

Panel.gameObject.SetActive (true);

CanvasGroups are your answer though if you want to bind the group of UI elements to a different corner of the screen as a group they should also be on their own Canvas

Here is the info you need to manipulate the CanvasGroup through code if you like.

I know pretty late to the party, but I created an onclick event you can attach to any button object that will show or hide another object without making the object inactive (in case you have to manipulate it while it’s inactive).

//to add to button object:

yourButton.onClick.AddListener(() => showHidePanelDynamically(insertObjectToHideHere));


    public void showHidePanelDynamically(GameObject yourObject){
        var getCanvasGroup  = yourObject.GetComponent<CanvasGroup>();
        if (getCanvasGroup.alpha == 0){
            getCanvasGroup.alpha = 1;
            getCanvasGroup.interactable = true;

            getCanvasGroup.alpha = 0;
            getCanvasGroup.interactable = false;

I hope this helps someone down the road!

Newer Post With Some More Info. Mainly The Video In The Thread.