private void Awake() { if (Instance != this) { Destroy(this); } else { DontDestroyOnLoad(gameObject); prefs = new PlayerPrefsHandler(); prefs.RestorePreferences(); currentlyLoadedProfileNumber = -1; SceneManager.sceneLoaded += OnSceneLoaded; } }
void Awake() { if (Instance != this || FindObjectOfType <EX1.DataService>()) { Destroy(this); } else { DontDestroyOnLoad(gameObject); prefs = new PlayerPrefsHandler(); prefs.RestorePreferences(); SceneManager.sceneLoaded += OnLevelWasLoaded; } }
private void Awake() { if (Instance != this) { Destroy(this); } else { DontDestroyOnLoad(gameObject); prefs = new PlayerPrefsHandler(); prefs.RestorePreferences(); #if UNITY_5_4_OR_NEWER SceneManager.sceneLoaded += OnLevelWasLoaded; #endif } }
// When the scene first runs ensure that there is only one // instance of this class. This allows us to add it to any scene and // not conflict with any pre-existing instance from a previous scene. private void Awake() { if (Instance != this) { Destroy(this); } else { DontDestroyOnLoad(this.gameObject); prefs = new PlayerPrefsHandler(); prefs.RestorePreferences(2); // In Unity 5.4 OnLevelWasLoaded has been deprecated and the action // now occurs through this callback. SceneManager.sceneLoaded += OnSceneLoaded; } }
// When the scene first runs ensure that there is only one // instance of this class. This allows us to add it to any scene and // not conflict with any pre-existing instance from a previous scene. private void Awake() { if (Instance != this) { Destroy(this); } else { DontDestroyOnLoad(gameObject); prefs = new PlayerPrefsHandler(); prefs.RestorePreferences(); // In Unity 5.4 OnLevelWasLoaded has been deprecated and the action // now occurs through this callback. //#if UNITY_5_4_OR_NEWER SceneManager.sceneLoaded += OnLevelFinishedLoading; //#endif } }
void OnLevelWasLoaded() { prefs.RestorePreferences(); if (SaveData == null) { LoadSaveData(); } // Set the player's progress if this is not the main menu scene. // Scene 2 and 3 are menus Scene activeScene = SceneManager.GetActiveScene(); if (activeScene.buildIndex > 3) { SaveData.lastLevel = activeScene.path.Replace("Assets/", "").Replace(".unity", ""); } WriteSaveData(); }
void Awake() { if (Instance != this || FindObjectOfType <EX2.DataService>()) { Destroy(this); } else { DontDestroyOnLoad(gameObject); prefs = new PlayerPrefsHandler(); prefs.RestorePreferences(); // Ensure that the player preferences are applied to the new scene // Using Lambdas: // SceneManager.sceneLoaded += (scene, mode) => prefs.RestorePreferences(); // Using functions: SceneManager.sceneLoaded += OnLevelWasLoaded; } }
void OnLevelWasLoaded() { prefs.RestorePreferences(); // If we haven't loaded any SaveData yet then load it. // This also sets the currentProfile number. if (SaveData == null) { LoadSaveData(); } // Set the player's progress if this is not the main menu scene. // In my project this is scene 0 and scene 1 Scene activeScene = SceneManager.GetActiveScene(); if (activeScene.buildIndex > 1) { SaveData.lastLevel = activeScene.path.Replace("Assets/", "").Replace(".unity", ""); } // Write the save data to file, saving the player's stats and progress. WriteSaveData(); }