Project 1C: Barrel Bouncer (UI & Scoring)

Part 3: A Player’s Three Lives

UI Setup

The steps to set up your UI for this section are as follows:

Your final result might look something like this:

Image showing 3 lives in upper right corner

Scripting Functionality

As you may recall from project 1A, one of the functions of a player controller is to keep track of the current player’s stats, like health and score. Thus you should create an int field for keeping track of the remaining lives in your Player Controller and set its initial value to 3.

In project 1B, you set up functionality for the player to “die” if they fall off the edge of the environment. Now, go ahead and decrement the number of remaining lives once this happens. You should also set up an OnDie event and trigger it once the player has died.

Finally, you should add a script to the Lives Container GameObject that subscribes to the OnDie event with a method that destroys one of its child GameObjects. Because of the way we set up the Lives Container, all the remaining hearts will automatically adjust to be positioned correctly (i.e. starting from the right and with correct spacing), and thus it doesn’t matter which child GameObject you destroy.

Previous Section | Go Home | Next Section