What I’ve done is use a modified singleton on the music player. So you keep the same music player/audiosource, but before destroying the new audiosource, you set the current audio source volume to the audisource volume on the new level. Make sense?
public class BackgroundMusic : MonoBehaviour
{
AudioSource audioSource;
void Start()
{
audioSource = GetComponent<AudioSource>();
SetupSinglton();
}
void SetupSingleton()
{
var players = FindObjectsOfType<BackgroundMusic>();
if (players.Length > 1)
{
// Because FindObjectsOfType doesn't return the objects in specific
// order, this bit of code will determine which player is the new one
// and which player is the old one
BackgroundMusic existingPlayer;
if (players[0].GetComponent<BackgroundMusic>().gameObject == this)
{
existingPlayer = players[1];
} else
{
existingPlayer = players[0];
}
existingPlayer.GetComponent<AudioSource>().volume = this.audioSource.volume;
}
else
{
DontDestroyOnLoad(this);
}
}
}
You can also modfiy this method to change the track between levels while keeping the AudioSource throughout. Let me know if you want that bit of code added in.