Damage VFX Using Animated Sprites in Unity
Mayday! I’m Hit!
2 min readMay 27, 2022
The next step in setting up visuals in my 2D Space Shooter is adding damage effects to the player when getting hit.
- I first added my damage sprite to the scene and positioned it at my preferred location. I duplicated this sprite and did the same. Then I set them as inactive in the Inspector.
I wanted one of them to be activated on the first hit, and the second one activated on the second hit.
- Inside the “Player” script, I added the following code.
[SerializeField]
private GameObject _leftEngine;
[SerializeField]
private GameObject _rightEngine;
- Back in Unity, I dragged the left and right engine sprites into their respective slots in the Inspector.
- Back inside the “Player” script I added the following code in the Damage() method.
I have animations to add to the damage sprites, so that’s what I did next.
- I selected the “Right_Engine” object and created a new animation called “Engine_Failure_anim”.
- I dragged the animation files into the Animation panel.
- In the Projects panel, I changed the name of the Right_Engine controller to “Engine_Failure”.
- With the “Right_Engine” object selected in the Hierarchy panel, I dragged the “Engine_Failure” controller to its respective slot in the Inspector panel.
- I then added an Animator component to the “Left_Engine” object.
- With the “Left_Engine” object selected in the Hierarchy panel, I dragged the “Engine_Failure” controller to its respective slot in the Inspector panel.
Testing the Player Damage VFX
Time to see how it looks. Fingers crossed.
Looks fabulous!