Creating a Health Collectible
While our Game is definitely fun to play, it would be much better if the Player had a chance to extend that fun! This can be achieved by creating a Health Pickup, increasing their Health, allowing them to play longer!
The logic is fairly simple, but it’s a necessary step for giving the Player more power!
Creating the Pickup
I tried pretty hard to find a suitable Health pickup that would fit the theme of the game. Unfortunately couldn’t find any that I liked, so I figured I’d make a really simple one. Turns out I really like this approach because it looks good and stands out.
This was simply made by Right-clicking in the Hierarchy, creating a 3D Object, of type 3D Text.
Then changed the Text to +1, changed the font size, and added the Powerup script, Box Collider, and Rigid Body.
As for the Animation, I had my Plus 1 Health Pickup selected in the Hierarchy, then clicked Create Animation in the Animation window.
I messed with the Mesh Renderer colours every couple of frames, and tweaked my sample rate down to 5 to control how fast the colours would change.
Plus 1 Health Logic
Now to give this Pickup some logic to do it’s job. First we update the Powerup script to include our Health Pickup:
Then inside out Player script, we create the Plus1Health() function:
This does nothing if our Lives are at max (3) already.
Otherwise, it adds 1 to our Lives, updates the UI, and also updates the Player Damage Indicators to reflect how much Health is left.
It’s a simple Pickup, but it will add longevity to your Game and the Players will thank you for it! Just don’t make it a super common Powerup to come by!
The next article we’ll be creating a Laser Sword! A new weapon of mass destruction to take down your Enemies even faster!