How to Play Sound Effects in Unity

Objective: Utilize sound effects in your game to give positive feedback to the player and more weight to your game.

Natalia DaLomba
2 min readJun 2, 2023

In this instance, we want our player to have the laser_shot audio clip play when the player shoots a laser.

First, add an Audio Source to the player object and and uncheck Play On Awake.

Go into your Player class and create a handle for the Audio Source component and call it audio. In Start, assign it to the Audio Source component on the player and null check it.

At the top, also create a Serialized Field AudioClip called laserClip. Then in the FireLaser method, assign that clip to the Audio Source audio. We do this in FireLaser instead of Start because there may be an explosion sound we want to play when the player dies and wouldn’t want the laser clip to be the default sound.

After assigning the clip, write audio.Play() to play the audio clip that is now assigned to the Audio Source component. It’s important this is called after the if and if else statements. So whether the player has the Triple Shot PowerUp active or not, the audio will play as long as they’re shooting.

--

--

Natalia DaLomba

A Unity C# developer inspired by game design logic used to create digital adventures. https://www.starforce.games/devlog/