How to Play Sound Effects in Unity

Simon Leen
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.

AudioClip and AudioSource created

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.

Assign and null check in start method

Finally in the ShootLaser method and calling the instantiate laser, play the laser using the audio source play call.

Play laser sound after shooting

In the next post, we’ll look at building and testing our game.

--

--