Creating Enemy Explosions

To play the above explosion animation when an enemy ship is hit by our Laser, we’re going to set a ‘trigger’ that activates an animation from the Animator.
First, we need to create a new Animation and drag the animation frames onto the animator. Now that we’ve created our animation we can edit the Animation Controller and add a new Trigger. We can create an ‘Empty’ state in our Animator and attach it to a Transition that uses the Trigger to activate the explosion animation:

Now all we have to do is add the trigger activation to the OnTriggerEnter2d method of the Enemy class:

As soon as SetTrigger executes, the new explosion animation will be played.