How to Play Sound Effects in Unity
Jun 11, 2021
Objective: Add sound effects to game objects.
Start by adding an Audio Source component to the Player and set play on awake to false in the inspector. Open the Player script and create a serialized private AudioClip and a private AudioSource.
Assign the AudioClip(laser sound) in the inspector. We will use a get component call within the script the assign the AudioSource as it allows us to run a null check on the object.
Finally in the ShootLaser method and calling the instantiate laser, play the laser using the audio source play call.
In the next post, we’ll look at building and testing our game.