I’ve been hit!
Damage VFX using Animated Sprites in Unity
Yesterday we took a look at creating explosion animations when our enemies were destroyed. Today, we’re going to give our player a visual indication of the damage that their ship has taken. This process is very similar in how we create and display the animation that represents our ships damage level. Most of the difference is in the code we use to display it. Let’s jump in!
First we create our new damage animation in much the same way as we did our explosions. We drag the first frame of our animation sprites into our hierarchy, rename it, open the animation window, click on the create animator button, name our animator, and drag the rest of our sprites into the dope sheet.
We then want to Prefab the animation by dragging it into our Project window into our prefabs folder. Next we want to drag it to below our Player object in our hierarchy to make it a child of the player so that it will move around with it. We’ll want to position it over one of our wings and then repeat the process of adding the prefab and positioning it for the other side.
Now we need to add fields to our player class and serialize them so that we can assign our damage visualizers. We’ll also do our due diligence and null check them and set them to disabled in our Start method of the Player class.
Now we can create a function to enable the visualizers based on our lives count and call it from our Damage function.
And now we can see the visualizers activating as we take damage!
Next Time!
Today, we learned how to give the user additional feedback on the state of their game through visual effects applied directly to the player in game! Next time, we’ll look at adding post processing to improve the overall look of our game. If you enjoyed this article, or want to come along with me as I progress on my journey, follow me at gamedevchris.medium.com.