Nerd For Tech
Published in

Nerd For Tech

From Explosions to Damage VFX

Damage VFX using Animated Sprites in Unity

Objective: Adding in some animations to when the player takes damage.

Adding the damage isn’t too different from adding in the explosions. Wait until a condition is met, turn on the animations. Maybe closer to the shield's power-up.

First, we are going to want to add in the animation for the damage. Drag the first frame into the Hierarchy, create the animation, line up the damage on the player. For help on animations, click Here.

Have to make Unity so small to be able to take Gifs that you can actually read anything lol.

If you move atm it will leave the new animation behind, we can fix this by making the damage a child of the player. By dragging the damage animation onto the player in the hierarchy, this will child the damage animation.

Now to make it so the damage only shows up when we take damage. Coding time!

In the player script, we will want to add the damage animations to the area where we get damaged, when we lose a life turn on the animation. The next part we could do with some If and Else If statements but let’s use a Switch statement instead.

Add in a reference for the GameObject that contains the damage animation, since we are going to add in damage to the left and right of the ship, add in 2 of these.

Since they are the same kind of GameObject, having them on the same line is fine.

Now to the damage method. After we take a life away let’s check how many lives we have left and depending on how many we have we can turn damage on/off. Doing this with IF and Else If statements it would look a little something like this, and also the switch statement we will be using.

All that’s left to do now is Duplicate the damage left, rename it to damage right and drop them into the reference we made on the player. We can turn them off to make it seem like they aren’t there and ready to be turned on when we do take damage too.

With all that done all that is left to do is test out that everything is working.

Looking good!

And with that, we went from no extra damage VFX to each time we get hurt a new one. Building on what we have already learned, we can implement new features to the game. You might have noticed that a bit lately, the same code was just used a little differently with an awesome result.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store