- Home /
UI Menus,Handling Menus.
Hi. I'm making a game with menus similar to Software Inc, in a window style.
I can currently drag these windows around, but my question is: How should I show / hide these windows? It's a GameObject with 2 images and a text object as children.
,Hello! I'm just starting my game making adventure on Unity and I have a few answers regarding how to go about making my first game.
I'm making a game with a lot of pop-up menus, similar to Software Inc., where you can move and resize menus. I'm currently at the point where I can move the menus around, but that's it.
My question is: How can I hide/show these menus? It's a GameObject which has some images and a text object as children.
Answer by ADiSiN · May 01, 2020 at 10:45 AM
You can disable/enable any GameObject class by .SetActive:
GameObject gameObj;
gameObj.SetActive(true);
gameObj.SetActive(false);
If you want to toggle from enabled to disabled without specifying it by true or false boolean you can do it this way:
gameObj.SetActive(!gameObj.activeself)
activeself it is current true/false statement of the GameObject and by adding
"!" mark before it we are reversing it's value. So if our GameObject is enabled it will disable, if disabled - it will enable.
However, you also can do it by disabling/enabling Image component specifically:
Image img;
img.enabled = false;
img.enabled = true;
This way you will disable Image component what will disable rendering of the sprite, but GameObj still will be enabled and you can do it to any other component attached to your GameObject.
Since as far as I understood there will be a lot of UI elements on your screen then I would suggest to dig in these tutorial about UI optimization: https://learn.unity.com/tutorial/optimizing-unity-ui?language=en in case you will find yourself in perfomance problem.