public void Awake() // Make sure there are no other instances of this gameobject { if (instance != null) { Destroy(gameObject); } else { instance = this; } }
public static HMGameController instance; // HMGameController is a singleton. HMGameController.instance.DoSomeThing(); // Ensure that the instance is destroyed when the game is stopped in the editor. public void OnApplicationQuit() { instance = null; }