Damage VFX using Animated Sprites in Unity

We want to show the player visually that they have lost a life.

Objective: add a visual effect to the player showing the ship has taken damage.

The first step is to drag the sprite that represents the damage into the hierarchy and make it a child object to the Player.

Next, we will resize it and move it into place on the ship. I will name it Right_Damage and set it to the foreground and layer 1 so it is on top of the ship.

Now that it in place we will create the animation.

Ok, next we will duplicate the object and place it on the left side, then rename it to Left_Damage. Also, we will need to deactivate them, so we can activate them when the Player is damaged.

Ok, now that we have the objects created we will focus on the code. First, we need to get a reference to objects. And assign them in the inspector. I created an array to store the objects.

Then in the inspector, we can set the size of the array and add the Left_Damage and the Right_Damage to the array.

Now that we have a reference to the left damage and the right damage, we can activate them when the Player is damaged and loses a life.

Now let’s see how it all works.

Happy coding!

Unity / C# Game developer