Hello Unity dudes,
So i have 1 scene (Main Menu) with my audio source and three more levels with a bunch of scenes. Every level has an Audio source with this script that plays music across scenes.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BGSoundScript : MonoBehaviour {
// Use this for initialization
void Start () {
}
//Play Global
private static BGSoundScript instance = null;
public static BGSoundScript Instance
{
get { return instance; }
}
void Awake()
{
if (instance != null && instance != this)
{
Destroy(this.gameObject);
return;
}
else
{
instance = this;
}
DontDestroyOnLoad(this.gameObject);
}
//Play Gobal End
// Update is called once per frame
void Update () {
}
}
It works like charm. But for example when you finish level 1 and you return to menu, you have 2 audios playing…when you start level 2 more audio source and so on.
So I would like to ask how do I manage this? Any thoughts?