My 90 day journey becoming a Unity game developer: Day-36

Rhett Haynes
2 min readJul 19, 2021

--

Objective: Add explosion sound effects to enemies, player, and asteroid.

We will start with the asteroid since it’s the simplest to set up. Let’s use the Explosion Prefab to add the explosion sound since the Explosion prefab is used on multiple game objects. Open the Explosion Prefab and add an Audio Source component. Drag the Explosion_Sound audio clip into the AudioClip slot and make sure Play on Awake is turned on.

Explosion audio clip added to Audio Source component.

In the Enemy script, we’re going to add a variable that will serve as the handle to the audio source component. Then in the Start() function, use the variable to gain access to the Audio Source component. Now we have 2 places where we need to use the variable when the enemy is destroyed. The first place is in the Player’s IF condition right before destroying the enemy’s ship. The second is in the Laser’s IF condition right before destroying the enemy’s ship.

Audio explosion clip set up using Audio Source to play before enemy’s ship is destroyed.
Audio explosion sound effects playing for laser and player destroying the enemy.

Next time we will add sound effects to the powerups.

--

--

Rhett Haynes
Rhett Haynes

Written by Rhett Haynes

Learning to become a Unity game developer.

No responses yet