void Awake() { if(!_instance){ GameObject.DontDestroyOnLoad(gameObject); _instance = this; AudioListener.volume = PlayerPrefs.GetFloat("sound", 0.5f); }else{ Destroy(gameObject); } }
// Create a static instance. void Awake() { if (Instance == null) { Instance = this; // Make sure this object isn't destroyed when a new scene is loaded. DontDestroyOnLoad(this.gameObject); // Play the music. OnLevelWasLoaded(0); } else { // Play the music. Instance.Play(this.clip); DestroyImmediate(gameObject); } }