Damage VFX using Animated Sprites in Unity
In the Day 20 blog post, we discussed adding VFX effects to our game by creating the enemy explosion effect. In today’s blog post, let’s add a damage effect to the player when they get hit.

To start, I’ll drag a fire sprite into the Hierarchy, scale it to an appropriate size, and position it on the left-wing side. Next, I’ll duplicate it and position it symmetrically to the first one on the right-wing side. Let’s drag them into the Player object as child objects, rename them, and give them the Foreground sorting layer and an Order in Layer of 2 so they are above the aircraft sprite.

Let’s also hide them when the game starts by unchecking the checkbox next to the cube icon in the inspector.

In our Player script, let’s declare them and assign them in the inspector:
[SerializeField] private GameObject _leftEngine, _rightEngine;
Once you’re done with that, let’s animate them as we did with the power-ups in the Day 13 blog post. Here’s the result:

Finally, let’s add the logic to unhide the sprites inside the Damage function:
if (_lives == 2)
{
_leftEngine.SetActive(true);
} else if (_lives == 1)
{
_rightEngine.SetActive(true);
} else if (_lives == 0)
{
_spawnManager.OnPlayerDeath();
Destroy(this.gameObject);
}
And voila, our game is working as expected!

In the next article, we’ll look at how to apply post-processing in Unity.