Immersion Starts with Sound

Objective: bring some life into our Unity game project by adding background music .

No game is complete without sound. Maybe it’s a musical riff looping in the background, or specific noises associated with the game environment like footsteps, weapons discharging, or even a voice narrating the storyline. Sound and music are an essential part of the experience, since they immerse the player into the world you’ve created.

Now is the time to journey into the Game Audio section of our 2D Space Shooter game project from GameDevHQ. This will be a two-part article, the first being a short read on how to introduce background music into your project.

Unity comes with a default Audio Listener attached to its Main Camera. Since the Main Camera tends to follow the Player, this makes sense in that the Audio Listener becomes the “ears” of the Player as it navigates through the game scenes picking up input from various Audio Sources along the way.

Background Music

The best way to proceed is to begin by creating a controller which will manage all of our game audio. We do this by creating an empty game object and renaming it Audio_Manager. Your next step is to create a new empty game object as a child to the Audio_Manager and call it Background_Music. We then attach a new Audio Source component to this child.

With the Background_Music selected in the Hierarchy, find the Audio Clip in the provided Assets called music_background, and attach it as the AudioClip of your Audio Source in the Inspector. Ensure you have Play On Awake and Loop checked on.

Just like that, you’ve added some background music to your 2D game that starts playing in a continuous loop the moment the game begins.

In our next section “How to Play Sound Effects in Unity”, we’ll explore how to add audio clip sound effects to specific game events such as firing lasers, explosions, and collecting powerups. Thanks for reading :)

Military member with 33+ years of service, undertaking an apprenticeship with GameDevHQ with the objective of developing solid software engineering skills.