public void Start() // Destroys this in case another instance is present { if (instance != null) { Destroy(gameObject); } else { instance = this; DontDestroyOnLoad(gameObject); } }
public static PB_Controller instance; // PB_Controller is a singleton. PB_Controller.instance.DoSomeThing(); public void OnApplicationQuit() // Ensure that the instance is destroyed when the game is stopped in the editor. { instance = null; }