Background music is a powerful component in any game. The music sets the tone and makes it easy for the player to allow themselves to connect with the game on a deeper level. Sometimes a solid game soundtrack is the hook that makes the game impossible to put down.
For example, a couple of my personal favorites are 1) the eerily haunting Diablo soundtrack that made it effortless to spend hour after hour immersed in the unfolding adventure quest and 2) the heavy-metal Full Throttle soundtrack that added an edge and made it exciting to become the rough-cut hero in an otherwise not-so-thrilling game (thank you, Gone Jackals).
Ok, time to add some background music. First we create a new GameObject, AudioManager, to act as our audio manager. The background music needs it’s own GameObject so let’s create another GameObject, Background, and make it a child of our AudioManager. We’ll need to add an AudioSource Component to our Background GameObject and set the Audioclip on it to the music clip we want to play.
If the Play On Awake and the Loop options are active, our clip will kick off at startup and loop as long as the game is running — no code required.