Damage VFX In Unity Using Animated 2D Sprites

Samantha Gittemeier
3 min readMay 27, 2023

--

Showing player damage is a great visual cue to let the player know they got hurt. In this article I’ll show you an example of implementing a player damage animation using our 2D sprites. If you read my Animating 2D Sprites In Unity article you should be pretty familiar with what we’ll do to make the animation.

Creating The Animations

I am going to be implementing this idea into my 2D space shooter. So for my game I will have the damage animation take place on both wings of my ship. First thing’s first, I need to make two children components for my player that I can set inactive in start, and then set active when my lives reach a certain point. So I will drag the first frame on my animation into my Hierarchy, scale it how I like, and then drag it onto my player so it becomes a child of my player.

Now I am going to create an animation the same way I did before. I’ll make a new animation clip by clicking create in my Animation window of my project. Now I’ll press record, drag in all my animation frames, and press record again to stop it. Now if I hit play I can see it animate. I’ll repeat the same process a second time so I have a child that will represent when my left wing is damaged, and then when my right wing is damaged.

Access, Assign, And Set Children Inactive

Now that I have my animations working correctly I need to access them, assign them, and set them inactive in my Start method of my player script. I will do this as I have all the other times by creating new Game Object variables for both damage animations, using Find(“Name”) to assign them, and using SetActive() to set them inactive.

public class Player : MonoBehavior

[Serialize Field]
private GameObject _leftWingDamage;

[Serialize Field]
private GameObject _rightWingDamage;

void Start()
{
_leftWingDamaged = GameObject.Find("Left Wing Damage");
_rightWingDamaged = GameObject.Find("Right Wing Damage");
_leftWingDamaged.gameObject.SetActive(false);
_rightWingDamaged.gameObject.SetActive(false);
}

Now when I hit start the animations are not automatically showing.

Setting Damage To Show

Now I need to set them to be active when my lives are at certain amounts. I will do this inside my Damage() method for my player script using if checks. I’ll tell my game that if my lives are less than or equal to 2, set my left wing damage active, and if my lives are less than or equal to 1, set my right wing damage active.

public void Damage()
{
if(_lives <= 2)
{
_leftWingDamaged.gameObject.SetActive(true);
}

if (_lives <= 1)
{
_rightWingDamaged.gameObject.SetActive(true);
}
}

Since I have 3 lives, this means on my first hit, damage shows on my left wing, on my second hit, damage shows on my right wing, and on my third hit I’m dead so there is nothing to show.

Now you know a quick and easy way to implement a player damage animation using animated 2D Sprites in Unity!

--

--