Space Shooter Challenge: Health Collectable

Calum Slee
Level Up Coding
Published in
2 min readMay 28, 2021

--

Let’s give the User a chance to regenerate Health.

Just like with the Ammo Powerup, I had to create a new one in Gimp. I was able to use the template I created for the Ammo Powerup, and simply recolor and change the text.

Again, drag the new Sprite into the Scene, then copy across the components needed for the powerups. The health powerup can have the next ID of 4.

Animate it, and make it a prefab. Then add it to the SpawnManager Powerup Array.

For the functionality, I once again created an int variable in the Powerup Script to allow us to assign different levels of health per powerup. Then in the switch statement added a new case.

To make this work, I need to create a public AddHealth method on my Player Script, requiring an int value to be passed through with it.

In this method, I only want to add health if the Player has less than the maximum amount of health. Incase I want to be able to increase the max lives in the future, I created an int variable to store this value. Then in my method, I can check if the lives are less than the max value of lives, before adding health.

Within the if statement, I want to add lives, then update the UIManager.

The visual damage effects also need updating. To tidy things up, I moved the switch statement for the damage visuals into it’s own method. Now when lives are added I can call this method, but I also need to call it when lives are deducted in the TakeDamage method.

I also need to flesh out the switch statement a bit more to dictate if visuals should be switched off as the lives increase.

--

--