- Home /
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 you should be using separate CanvasGroups for each group of UI elements, then you can hide, show or animate each group with it's CanvasGroup container
Answer by FWCorey · May 29, 2015 at 10:00 AM
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.
Thanks, but how do you add a CanvasGroup? I can't seem to find it anywhere. $$anonymous$$aybe it's new to v5? I've still got 4.6, so just updating.
EDIT: Found it. It's a component under "Layout", I didn't think to look there.
Answer by mafanbong8819 · Feb 25, 2017 at 05:12 PM
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);
this doesnt seem to work for me. the panel is not active but its still visible
in start panel.setActive(false) then set it to true in desired function
Answer by shoopscooper · Nov 12, 2019 at 12:59 AM
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));
//method:
public void showHidePanelDynamically(GameObject yourObject){
var getCanvasGroup = yourObject.GetComponent<CanvasGroup>();
if (getCanvasGroup.alpha == 0){
getCanvasGroup.alpha = 1;
getCanvasGroup.interactable = true;
}else{
getCanvasGroup.alpha = 0;
getCanvasGroup.interactable = false;
}
}
I hope this helps someone down the road!
Answer by Reedex · Oct 31, 2019 at 10:20 AM
Newer Post With Some More Info. Mainly The Video In The Thread. https://forum.unity.com/threads/canvas-off-on.753221/#post-5048900
Your answer
Follow this Question
Related Questions
How to get offset of a ScrollRect? 0 Answers
Figure out the pixel size of a character 1 Answer
Using iTween with the new Unity UI 2 Answers
Why wont my text box stay the same size? 2 Answers
[4.6 GUI] Displaying my pause menu when ESC is pressed 2 Answers