Creating Immersion with Sound
Although sound is essential in building an immersive environment, it tend to be undervalued or even overlooked by starting game developers. Sound helps dictate what the player should feel. Play a slow piano melody and you can change the tone to somber. On the other hand, switch it to a fast beat tune and the tone suddenly switched to exhilarating.
However, before we start choosing which sound we want to play, we must first implement it in our scene.
By default, Unity has put the Audio Listener on the Main Camera. Because you can only have one active Audio Listener at a given time, if you want another game object to have the listener, remember to disable or remove it from the Main Camera to ensure you won’t get an error like this:
First, decide which object you would like to use for the background. Depending on the type of game you’re making, the Main Camera would make sense. However, creating an empty game object and using that as an Audio Manager is good practice as you will not be relying on the camera and doesn’t require you to access the Camera in order to obtain the Audio source.
Once you’ve decided, go to the Inspector panel and select Add Component. Search for Audio Source and select it.
After you selected it, you now have a component that will accept your Audio clip!
Depending on the music you’re playing, like background music, it might be advantageous to check both “Play On Awake” and “Loop”. On the other hand, for some audio clips, like sound effects, it might be better to not play the clip right away or in a loop.
If you do check both boxes, this will cause the audio clip to play automatically once you start the game, whether it be clicking on Play or in a finished build, and loop once the clip is complete.