Phase I — Progress report — Health pickup

In this update, I will go over the health pick-up I have implemented. This one required a change I didn’t think about when first implementing the system but I’ll cover that after the core functionality.

I’m not an artist by any means so I just thew 2 sprites together in paint and animate through them so they have a bit of life to them.

As this is a powerup essentially I could reuse the powerup script, adding a new id in the inspector and dropping the prefab into the array in the spawn manager.

I added a new function player which added another life to the player if they were not already at max lives, just preventing the player from going over the max lives allowed.

The UI manager actually did not need any changes made to functionality in order to add lives and update the sprite which again shows the power of forward-thinking and modular scripts.

There are 4 sprites 4 potential states. Lives can be any of the following 3,2,1,0.

Next, we get to the bug I created. When we take damage the lives sprite gets updated and the player gets a fireball under a random wing.

When we add health we were updating the sprite but the fireballs were not being taken away. To counter this I added in an optional bool and a new local variable in our fireball function.

The optional bool gives the function a default value if the bool parameter is not passed in when calling the function. This means we don’t have to edit any existing function calls. We then tell the function if we are taking damage (bool is true) to set the game object active status to true as well (same as the bool). We then add in a variable that takes the “taking damage” bool and reverses it (true to false and vise versa).

This means in our check to see if the game object is active already we can automatically determine if we are trying to activate it or deactivate it. For example, if the taking damage bool is set to true, we check to see if the game object is false (the reverse) and then set it to the same value as our bool (in this case true).

It sounds complicated but let's see it in action.

That's all for now.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store