Damage VFX using Animated Sprites in Unity

Ryan McCoach
3 min readApr 20, 2021

--

In this article, we are going to add some Visual Effects to the player when they lose a life by showing an engine failure. This method of adding an animation is different approach compared to the enemy explosion (previous article). The enemy explosion required adding a custom made animation to the Enemy that was controlled using the Animator through code.

In this approach, we are going to add animations using GameObjects. First, we add the first imagine of the engine failure to the Player making it as child of the Player. After repositioning it to the wings and scaling it to size, you will make a duplicate so you have a Left_Engine and Right_Engine failure GameObject. With both of these objects as children of the player, they will move with the Player.

We are going to select one of the two Engine GameObjects, and create an Animation with the rest of the Engine Failure Sprite images. Once we create the animation for one engine, we can add an Animator Component to the other engine and drag the newly created Engine Failure Animation into the Animator. Now, we have Engine Failure Animations for both Engines.

After we have the animations running on the Engine GameObjects, we do not want these GameObjects active when the game first starts because they are suppose to represent a loss of a life.

Select the GameObjects and uncheck the boxes next to the name of the GameObject in Inspector to deactivate them.

Through script, we can simply just activated these GameObjects when we need them to be activated. But first, we need to assign both the Left and Right Engine GameObjects to the Player script so we add a Serialize Field attribute to these GameObject variables.

Now, we have access to both of these GameObjects we want to set them active when the Player losses a life. Using IF and ELSE IF conditional statement to check the lives remaining and depending on how many lives the player currently had will determine what Engine GameObject to turn or SetActive(true). Since the Engine Failure Animation is already on each of the Engine GameObjects, it will play when they are activated.

--

--

No responses yet