My 90 day journey becoming a Unity game developer: Day-35
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.
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.
Next will be adding an explosion sound.