Homing missiles — Cosmetics!

Objective: Implement a sprite and explosion with the homing missiles.

With the last tutorial I showed you how to create a basic homing missile system. Today, we are going to use a sprite and add an explosion animation. This is simple and give your game that same polish treatment we have given the rest of our assets so far.

To begin you need to either create a sprite or download one from the asset store. I’m using the missile sprite from this.

Now place the sprite into the hierarchy and rotate to the face downwards. Add the same components from the stand in missile we already made and copy the values.

When the missile detects collision, we want to set the trigger for the animation to begin. I’m using the same method I used for the enemy’s explosion.

We make a trigger parameter for the animation

The next thing I want to do is set the sorting layers. Place both the missile launching enemy and the missile on the foreground layer. Give the enemy a larger number then the missile this way the missile spawns below the enemy. This is a different projectile and though should be launched from a different gun i.e., location.

Layering is important, don’t forget

Finally, since we have an explosion we need the accompanying sound FX to go with it. Add the component audio source and attach the sound FX for the explosion. Make sure to uncheck the “play on awake” box and in the code we need to create a handle for the audio source.

Simply add where you want the sound to play and presto, you have a nice sounding explosion to go with your missiles.

This is it, now the homing missile works and looks tones better. As always, don’t be afraid to experiment with your code, and I’ll see you in the next tutorial.