Creating the Visuals

For our game example, the only elements we will be using are a health display and a coin display. The health display will show the health of our player as they take damage in the world and how much they have left before going “kaput.” The coin display will show the current number of coins and will change as the player collects more and more of them.

But the first thing we need is an empty GameObject where we can store all of our HUD GameObjects and scripts. HUD elements are on-screen elements that sit in front of the player view and do not interact with the game world. As such, we should treat them as their own unique element within the Scene.

1. Open the Chapter 10 Scene.

2. Create a new empty GameObject and rename it “HUD.” ...

Get Learning 2D Game Development with Unity®: A Hands-On Guide to Game Creation now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.