private void Awake() { if (HUD == null) { DontDestroyOnLoad(gameObject); HUD = this; } else if (HUD != this) { HUD.transform.position = gameObject.transform.position; Destroy(gameObject); } }
private void Awake() { //Check if instance already exists if (instance == null) { //if not, set instance to this instance = 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); } DontDestroyOnLoad(gameObject); }