public void OnClick() { // Note that a simple for loop cannot be used because // as we remove controls, the incrementing index will // no longer be correct while (target.Controls.Count > 0) { // Reference the first control in the container var childControl = target.Controls[0]; // Remove the container from the control before // destroying it target.RemoveControl(childControl); // Destroy the control DestroyImmediate(childControl.gameObject); } }
public void RemoveMarker(dfRadarMarker item) { if (markers.Remove(item)) { ensureControlReference(); if (item.marker != null) { Destroy(item.marker); } if (item.outOfRangeMarker != null) { Destroy(item.outOfRangeMarker); } control.RemoveControl(item.marker); } }