private void Awake() { if (instance == null) { instance = this; } //if instance already excists and it's not !this else if (instance != this) { // Then destroy this. This enforces our singleton pattern, meaning that there can only ever be one instance of a GameObject Destroy(gameObject); } //To not be destroyed on loading scene DontDestroyOnLoad(gameObject); }
private void Awake() { //check if instance already exists if (instance == null) { instance = this; } //If intance already exists and it is not !this! else if (instance != this) { //Then, destroy this. This enforces our singletton pattern, meaning rhat there can only ever be one instance of a GameManager Destroy(gameObject); } //To not be destroyed when reloading scene DontDestroyOnLoad(gameObject); }