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