public void Delete() { GameObject[] selection = Selection.gameObjects; if (selection == null) { return; } Undo.BeginRecord(); for (int i = 0; i < selection.Length; ++i) { GameObject selectedObj = selection[i]; if (selectedObj != null) { Undo.BeginDestroyObject(selectedObj); } } Undo.RecordSelection(); Undo.EndRecord(); bool isEnabled = Undo.Enabled; Undo.Enabled = false; Selection.objects = null; Undo.Enabled = isEnabled; Undo.BeginRecord(); for (int i = 0; i < selection.Length; ++i) { GameObject selectedObj = selection[i]; if (selectedObj != null) { Undo.DestroyObject(selectedObj); } } Undo.RecordSelection(); Undo.EndRecord(); }