How to Play Sound Effects in Unity

Anurag Chawla
2 min readMay 20, 2021

Sound mechanics is very important in any game- It makes player engage throughout the journey from start to finish.

As seen in my last articles, we are going through our Galaxy shooter 2D game using Unity. Implementing sound effects in unity by using different audio files with different variation as below.

1. Background clip — Here, create a new empty GameObject — called AudioManager. On this manager, we will create a new empty GameObject, called Background and here we will add a new component, Audio Source. Audio source has a property of AudioClip where we assign the music_background from dragging from the folder -Audio under Assets.There are few other properties we can assign as when to play sound effects such as play on awake or keep looping.we can set the Priority, Pitch,Volume etc

Added music_background to AudioClip for Audio Source Component.

2. When player fire- Laser shot — Here we added the Audio Source component to the Player, other properties are not checked such as Player on awake /loop.

The _laserSoundClip will get populated in the ‘Inspector’ with the ‘laser_shot’ sound effect when AudioClip reference in player script i.e, Player.cs file .

In addition AudioSource is also reference in the Player Script using GetComponent and later called during FireLaser() method

Added AudioSource Component to Player Object, Ref laster_shot to player property Laser Audio Clip
Added AudioClip and AudioSource variables reference programmatically in Player.cs Script
audioSource.Play() method called for Sound Effect

In this article , I have shown 2 ways to implement sound effects , but there are many more ways to implement the sound effects based on the use-cases and scenarios hows your game evolving and how one makes player engaging in different activities.

--

--

Anurag Chawla

Emerging Technologies - Power Virtual Agents | AI Chatbots | Multi-Cloud & DevOps | UI Technologies - React , Angular | Gaming Technolgies - Unity, XR- AR/VR