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