-
Notifications
You must be signed in to change notification settings - Fork 0
How Menus work
The kind of menu management that is used in this project was and will be used in many Unity projects of mine. There are only two necessarry classes.
- MenuController: The heart of the menu management. This class has all the opening and closing functionality as well as a list of active menus at all time. It automatically stacks menus on top of each other and pauses/resumes the game if necessarry.
- MenuParent: Not really important. This is just a parent for all menu scripts which only references the MenuController so that doesn't have to be done in every menu.
The new menu script needs to be a child of MenuParent. To open or close the menu, the Open() and Close() methods of MenuController, which is referenced in the MenuParent, need to be used. Also its important to make sure that the new menu script is attached to the parent element of the elements of the menu (buttons, text etc.). The MenuController will disable that parent element and like that deactivate the whole menu.
The main menu is the one that is opened with Escape and is usually used to hold at least the "exit game" button. This special menu needs to be referenced in the MenuController. It usually is the first menu to implement since everyone wants a closing feature. The whole Escape pressing stuff is already handled in the MenuController.
The same goes for every other menu that should be opened by a button press (Inventory on I f.e.). This menu should be referenced in the MenuController and the Escape button functionality in the MenuController.Update() function should simply be copied for every other key.