void Awake() { if (instance == null) { instance = this; DontDestroyOnLoad(gameObject); SceneManager.sceneLoaded += OnSceneLoaded; } else if (instance != this) { Destroy(gameObject); } }
// Singleton private void Awake() { if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } DontDestroyOnLoad(gameObject); }
// Start is called before the first frame update void Awake() //Awake is called right before start { if (isPlaying == null) { DontDestroyOnLoad(transform.gameObject); isPlaying = this; } else if (isPlaying != this) { Destroy(transform.gameObject); } if (PlayerPrefs.HasKey("MusicVolume")) { musicVolume = PlayerPrefs.GetFloat("MusicVolume"); mainTheme.volume = musicVolume; } else { musicVolume = 0.2f; mainTheme.volume = musicVolume; } }