[SOLVED] Static Bool instead of MusicPlayer instance?

I tried this during the challenge and it worked. Is there a downside to this code compared to the instance/null way you showed?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MusicPlayer : MonoBehaviour {

    static bool musicPlayer = false;

	// Use this for initialization
	void Start () {
        if (!musicPlayer) {
            GameObject.DontDestroyOnLoad(gameObject);
        } else {
            Destroy(gameObject);
            print("Destroyed duplicate MusicPlayer");
        }
        musicPlayer = true;

	}
	
	// Update is called once per frame
	void Update () {
		
	}
}

Answer found in this thread.
https://community.gamedev.tv/t/solved-using-boolean-instead-of-instance-this/20517

Privacy & Terms