Visual Effects in Unity

Brian Ratnasinghe
3 min readJun 30, 2021

--

Here I will discuss animated visuals in Unity and how to implement them. In this case we will be looking at the Enemy GameObject which will be animated to explode on hit. You can see that I have a folder called “Enemy_Explode_Sequence” where I have all the frames of the remade explosion animation. I dragged all of these frames into animator window and saved the animation as Enemy_Destroy_anim.

Following the steps above will automatically create an animator component for the GameObject or prefab if they were previously select, our you can create the component manually after the fact.

Now, let’s check out the controller in the animator component to open up an animator tab. This tab allows us to control when animations are played. By default the animation will be set to play immediately upon entry which is not ideal.

First right click an empty space to create an Empty state that will serve as a buffer between the Entry State and the animation. The result should look something like this this.

In this configuration one can access the transition between the empty state and animation in order to add a condition for the animation to play. To accomplish this one can click on the parameters tab on the left, then click the plus sign to create a trigger condition. I titled by Trigger “OnEnemyDeath” because that is when the animation needs to play.

Next, select the arrow between empty and the animation to apply the trigger condition to the transition using the Inspector Tab. Next, be sure to make to uncheck the Exit Time box and set the Transition Offset to 0 to make sure there is no delay in triggering the animation.

Now, code can implemented to meet the condition and play the animation. First, the animator needs to be declared and assigned in the Start method.

Finally, the SetTrigger function is able to be called on the animator to play the animator. Of course, one to needs to delay the destruction of an object once this happens to allow the animation to play out. I did this, by using a float argument in the destroy method but there are other ways. Anyways, here is the code.

Here is the final result. Thank you for reading.

--

--

Brian Ratnasinghe

Here I am documenting everything I am learning in order to become a successful game developer.