//------------------------------------------------------------------------------------------------------------------------ // Destroy() //------------------------------------------------------------------------------------------------------------------------ /// <summary> /// Destroy this instance, and removes it from the game. To complete garbage collection, you must nullify all /// your own references to this object. /// </summary> public virtual void Destroy() { if (!game.Contains(this)) { return; } OnDestroy(); //detach all children while (_children.Count > 0) { GameObject child = _children[0]; if (child != null) { child.Destroy(); } } //detatch from parent if (parent != null) { parent = null; } //remove from game if (Game.main != null) { Game.main.Remove(this); } }