void Awake() { // First we check if there are any other instances conflicting if(Instance != null && Instance != this) { // If that is the case, we destroy other instances Destroy(gameObject); } // Here we save our singleton instance Instance = this; // Furthermore we make sure that we don't destroy between scenes (this is optional) DontDestroyOnLoad(gameObject); }
void Awake() { // First we check if there are any other instances conflicting if (Instance != null && Instance != this) { // If that is the case, we destroy other instances Destroy(gameObject); // In some very rare cases, you may need to use DestroyImmediate instead // DestroyImmediate(gameObject); } // Here we save our singleton instance Instance = this; // Furthermore we make sure that we don't destroy between scenes (this is optional) DontDestroyOnLoad(gameObject); }