Chapter 6. Putting a 2D GUI in a 3D game

 

This chapter covers

  • Comparing old (pre-Unity 4.6) and new GUI systems
  • Creating a canvas for the interface
  • Positioning UI elements using anchor points
  • Adding interactivity to the UI (buttons, sliders, and so on)
  • Broadcasting and listening for events from the UI

In this chapter you’ll build a 2D interface display for a 3D game. So far, we’ve focused on the virtual scene itself while building a first-person demo. But every game needs abstract interaction and information displays in addition to the virtual scene the gameplay takes place in. This is true for all games, whether 2D or 3D, first-person shooter or puzzle game.

These abstract interaction displays are referred to as the UI, or more specifically the GUI. GUI refers to the visual part of the interface, such as text and buttons (see figure 6.1). Technically, the UI includes nongraphical controls, such as the keyboard or gamepad, but people tend to be referring to the graphical parts when they say “user interface.”

Figure 6.1. The GUI (a heads-up display, or HUD) you’ll create for a game

Although any software requires some sort of UI in order for the user of that software to control it, games often use their GUI in a slightly different way from other software. In a website, for example, the GUI basically is the website (in terms of visual representation). In a game, though, text and buttons are often an additional overlay on top of the game view, a kind of display called a HUD.

6.1. Before you start writing code...

6.2. Setting up the GUI display

6.3. Programming interactivity in the UI

6.4. Updating the game by responding to events

6.5. Summary

sitemap