Game Development Reference
In-Depth Information
Adding Buttons to the Main Menu
The main menu graphic in Figure 8-4 already features the button graphics “built-in”—that is, the
image already features the button objects. In most games, this will not be the case. Typically,
GUI button graphics are isolated as separate sprites and are overlaid atop the menu background
to support additional functionality, such as animations and hover states when the cursor moves
over the buttons. But here, the buttons are built into the menu, and this will still serve our needs.
Now, there are many ways the button functionality could be handled in CMOD; for example, each
button could detect presses as they happen, and then internally handle the responses, performing
appropriate on-click functionality. But for CMOD, our buttons will be “hollow” in the sense that
they'll exist only to detect button presses , and then they'll trigger a system-wide event using the
NotificationsManager, allowing any other listening processes to respond as needed when clicks
happen. Other processes, if any, will essentially handle button presses. To get started on creating
clickable buttons, create five new game objects, one for each button, as children of the menu,
resetting their transforms to (0, 0, 0). The buttons are named button_Cancel , button_Exit ,
button_Load , button_Restart , and button_Save (see Figure 8-9 ).
Figure 8-9. Adding button objects to the scene as children of the menu object
Next, add a Box Collider component to each button object ( Component Physics Box Collider )
to approximate the button volume on-screen to allow click detection. Use the Game tab to align
the colliders with the button graphics on the menu in the viewport. Remember, if you don't see
the collider gizmo outline in the Game view, then click the Gizmos drop-down box to enable the
Colliders option (see Figure 8-10 ).
 
Search WWH ::




Custom Search