private void Awake() { // http://clearcutgames.net/home/?p=437 // First we check if there are any other instances conflicting if (_instance != null && _instance != this) { // If that is the case, we destroy other instances Destroy(gameObject); } // Here we save our singleton instance _instance = this; // Furthermore we make sure that we don't destroy between scenes (this is optional) DontDestroyOnLoad(gameObject); }
void OnApplicationQuit() { _instance = null; // release on exit }