void Awake() { if (instance != null && instance != this) { Destroy(this.gameObject); return; } else { instance = this; } DontDestroyOnLoad(this.gameObject); }
private void Awake() { DontDestroyOnLoad(this.gameObject); if (instance == null) { instance = this; } else { Destroy(this.gameObject); return; } }
void Awake() { if (dontDupe) { //Check if instance already exists if (Dontdestroy == null) { //if not, set instance to this Dontdestroy = this; } //If instance already exists and it's not this: else if (Dontdestroy != this) { //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager. Destroy(gameObject); } } }