void Awake() { DontDestroyOnLoad(this); if (musicInstance == null) { musicInstance = this; } else { Destroy(this.gameObject); } if (audioSource != null) { if (SecurePlayerPrefs.GetInt("music", 0) != 0) { audioSource.Pause(); } else { if (!audioSource.isPlaying) { audioSource.Play(); } } } }
// Use this for initialization void Awake() { if(Instance == null) { //If I am the first instance, make me the Singleton Instance = this; DontDestroyOnLoad(this); } else { //If a Singleton already exists and you find //another reference in scene, destroy it! if(this != Instance) { Destroy(this.gameObject); } } }