2D Shooter: Health Collectible

Objective: Add a collectible that gives the player another life.

Creating the visual for this powerup is much like the previous we’ve made, except this will have a powerupID of 4 and will be case 4 in the switch statement in the powerup script.

In the switch statement we’ll have it call a method we will make in the player script that will increase the life.

We don’t want life to go above 3, so let’s make sure we set it back to 3 in case the player collects a heart when at full health. We also need to make sure to update the UI display.

Now for spawning, I want it to be another enemy drop, so we’ll add an or statement in that method to include the heart collectible.

And now it’s done!