Visualizing Player Damage

Matej Marek
3 min readApr 26, 2021

--

Now that our enemies are exploding, it is time for our player to show some signs of getting hit. Right now, this can be seen in our UI implementation, but if the player is too focused on the game, he might not realize that he got hit in all of the chaos. Since we have three lives, the objective is to show different ship stages at different life values.

Due to technical problems, I had to borrow this footage from the GDHQ video.

For this reason, I have created an animation of a fire, which I have turned into a Prefab. I also placed two of these Prefabs directly on our Player GameObject in the Hierarchy as players' Children GameObjects.

With this done, all that we need to do is to adjust the ‘Player’ script a bit.

First, we need to get a reference to the children's GameObjects and set them as not active at the start of the game since our player starts with three lives.

Finally, we need to define where and when we should activate the fires. And that is in the ‘Damage()’ method in the ‘Player’ script.

And this is how we do it, a simply if-else statement, checking for the value of players’ ‘_lives’ variable. When the player loses one life, the first fire is activated - and when he loses another, both fires are active at the same time.

All that remains is to maybe play an explosion when the player dies. This can be done the same way as we did in the previous article on the Asteroid!

Now, whenever the player takes damage, the ship will get a fiery visualization, and if he manages to take three hits altogether, he perishes in an explosion!

But that is it for now, thank you for reading and feel free to follow me for more articles - and as always, good luck and see you next time!

--

--

Matej Marek
Matej Marek

Written by Matej Marek

Aspiring and eager beginner Unity developer

No responses yet