Player Damage VFX using Animated Sprites in Unity
The basic principle when dealing with animated sprites in Unity is the same no matter what it is being used for (click here to know more). In the previous article we implemented Enemy explosions, this is going to build upon it as we now add a player damage visual effect using the same principle.
Let’s start by creating a visual cue to indicate that the Player has been damaged.
How about we animate the effect shown above effect.
The Player at the moment has three lives, implying that if we were to add a visual cue to show that he has been hit (other than showing it in the UI) we could show an effect, as when the player has 3 lives left he is unscathed, 2 lives he has taken a hit display the hurt effect, 1 life display it twice and finally 0 lives destroy the object.
So let’s duplicate the hurt game object and make them a children to the Player. Doing so will let the effect move along with the Player.
With the Damage VFX ready, let's have them show up when the Player takes damage.
Ternary conditional operator is denoted by “?:” and it implies,
So in the above Player behavior script we’re checking if the player has 2 lives left then display the LeftEngineHurt game object, if the player has 1 life left then display the RightEngineHurt game object. (This is all done with the assumption that each enemy deals unit damage and that the Player has a maximum of 3 lives).
Doing the above gives us the following result,
Thank you for reading. More to come!!!