void Awake() { if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } DontDestroyOnLoad(gameObject); }
/// <summary> /// Awake is called when the script instance is being loaded. /// </summary> void Awake() { instance = this; }