void OnDestroy() { if (ins == this) { ins = null; } //do something clean up foreach (var p in GameObject.FindObjectsOfType <RemoveOnLevelChange>()) { GameObject.DestroyImmediate(p.gameObject); } if (this.player != null) { GameObject.DestroyImmediate(this.player); this.player = null; } }
void Awake() { ins = this; }