Hey guys, so I want the MusicManager game object to continuously play with new scenes loading in. The code below works, but does not archive what I wanted. There’s a game over state. And when the player is in that state, the scene restarts.
Let me firstly explain what’s going on inside the code: MusicManager detects another music manager, it destroys the one which is current inside “DontDestroyOnLoad” stage.
The code would work, but for some scenes, I added my own MusicManager to change the music playing in that scene, and because of this, whenever the scene restarts, the music also restarts…
public class MusicManager : MonoBehaviour
{
static MusicManager instance;
private void Awake()
{
CheckInstance();
}
void CheckInstance()
{
// This gets check with every MusicManager
// UNLIKE LOCALS, THE GLOBAL INSTANCE WILL ONLY CHECK ONCE ON AWAKE
if (instance == null)
{
instance = this;
DontDestroyOnLoad(instance.gameObject);
}
else
{
Destroy(instance.gameObject);
}
}
}
Any advice are appreciated! Thanks in advance.