private void OnDestroy() { if (current == this) { current = null; } }
private void Awake() { if (current == null || current == this) { current = this; } else { Destroy(gameObject); return; } DontDestroyOnLoad(gameObject); }
public static UnityThread CreateUnityThreadInstance(bool visible = true) { if (current != null) { return(current); } if (Application.isPlaying) { var obj = new GameObject("UnityThreadRunner"); obj.hideFlags = visible ? HideFlags.HideAndDontSave : HideFlags.None; current = obj.AddComponent <UnityThread>(); } return(current); }