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

Rhett Haynes
2 min readJul 17, 2021

--

Objective: Add sound effects to the player’s lasers when shot.

Select Player and add an AudioSource component. Turn off Play on Awake so the audio clip won’t play right away when the game starts.

Audio Source added to the player with Play on Awake turned off.

Go to the Player script, create a variable to store the audio clip for the laser. Also, create a variable to access the player’s audio source component. In the Start() function, use the audio source variable to actually get the audio source component. We will null check it and if it passes the null check, then add the audio clip to the audio source itself.

Go to the Laser() method, use the Play() function on the audio source to play the laser sound clip.

Click on Player in Hierarchy, go to the Player script component and drag the laser sound clip into the variable’s slot.

Laser sound clip added to the variable’s slot.
Laser sound plays every time the player shoots.

Next will be adding an explosion sound.

--

--

Rhett Haynes
Rhett Haynes

Written by Rhett Haynes

Learning to become a Unity game developer.

No responses yet