Unity MusicManager and Music Playlist (C#)
The Music Manager is intended for playing music. Many games have background music that plays independently of sounds. Some games may want music to persist from scene to scene or stop and then restart where it left off. The Music Manager is a singleton persistent game object intended to ease in the production of this.
MusicManager.cs should be added to an empty game object in the splash scene, this way it persists from scene to scene.
The Music Manager is capable of automatically fading in music when it loads, making for nicer transitions into a scene. The Fade Duration can be set in the inspector.
The Music Manager is best used with Music Playlists. A Music Playlist is an empty game object with the MusicPlaylist.cs script attached. MusicPlaylist.cs takes an array of audio clips. I recommend leaving the ‘Play On Awake’ option checked, this way the Music Manager will begin playing the playlist as soon as the scene is loaded. Each playlist should be set in the first scene in which the playlist is to be played.
The Music Manager automatically keeps playing the current playlist when the scene changes, unless the new scene has a playlist object. When a new playlist object is encountered, all other playlist objects are destroyed and the Music Manager loads the new playlist and begins playing it, possibly with a fade-out and fade-in if the Fade Duration is set in the Music Manager.
It is assumed each scene requiring a new playlist will have only one MusicPlaylist object. As of this post, there is no error handling if a scene has multiple playlist objects in the hierarchy.
I highly recommend watching the YouTube overview to understand how the music manager and music playlist systems work.
YouTube Overview and Demonstration
Next Up: Sound Manager
The sound manager is in charge of playing sound clips such as explosions, projectiles, etc. It is independent of the Music Manager so that sound effects can be controlled separately from background music. Read about the Sound Manager here: https://www.zesix.com/2015/02/unity-soundmanager-c/