Simple approach

I took a slightly different approach. Rather than storing an instance of the MusicPlayer, I used a bool and set to false initially.

Then, on load I check the bool It’s essentially the same as using the music player. Ultimately it does the same.

Code as follows:

static bool isPlaying = false;

// Use this for initialization
void Start()
{
if ( isPlaying )
{
Destroy( gameObject );
}
else
{
isPlaying = true;
GameObject.DontDestroyOnLoad( gameObject );
}
}

Privacy & Terms