void OnDestroy() { if (thread != null) { thread.Terminate(); } // clean up global value instance = null; initialized = false; }