Spaceship Game Made with Unity: Adding Explosion SFX
Objective: Add an Explosion SFX when Player/Enemy/Asteroid explodes.
In this case we have different objects with the same SFX so let’s get into it. First I Added an AudioSource component to the “Explosion” prefab, checked the “Play On Awake” and assigned the audio clip.
This works for the asteroid because the sound is gonna be played when the explosion prefab is instantiated.
Now for the Enemy I created a new empty GameObject called Explosion as a child of the Audio Manager, unchecked the “Play On Awake” value and assigned the clip.
In the enemy script I created a variable to store the explosion object and used the GameObject. Find method to find the reference.
And in the Explode method I just call the function Play.
Good to go! We have a functional explosion SFX for all cases in the game.