Player Damage Visual Effect

Our next goal is to add some visual effects to the player to show when they are damaged. This will provide an additional indicator, so the player knows when the ship has been damaged.

First, we need to create the GameObject for the visual effect. We do this by dragging the first frame of the Player_Hurt animation into the Hierarchy and making it a Player child.

Next, we can resize it to about 1on all axes then move it to the right wing of the player ship. We also need to change its sorting layer to Foreground and set the Order in Layer to 2 to appear over the ship.

Next, we will add the animation for the damage.

Now we will duplicate the damage object and move the copy over to the left-wing. Then we’ll change the names to Right_Engine_Damage and Left_Engine_Damage.

In the Player script, we need to reference the right and left engine damage objects. We do this by adding the following lines.

After saving the script, we go back into the Inspector and drag the right and left engine objects into their respective places in the Player script. We also want to disable both in the inspector since they should start that way when the game starts.

Next, we go back into the Player script and use an if statement to check the Player’s lives. If the Player has 2 lives left, we will enable Right_Engine_Damage, and if there is 1 life left, we will enable the Left_Engine_Damage.

We can see below that now, when our player is hit that the damage animations show for each wing in turn.

I hope you found this article informative and enjoyable. And, as always, I wish you luck on your coding journey.



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