public IEnumerator _ClearUnit(bool showDestroyEffect = true, float delay = 0) { destroyed = true; //if the unit is spawned from a spawner for a parcicular wave, inform the spawner that a unit in the wave is cleared if (spawner != null && waveID >= 0) { spawner.UnitCleared(waveID); } //remove the unit from UnitTracker and inform GameControl (to check for objective) if (hostileUnit) { UnitTracker.RemoveUnit(this); GameControl.UnitDestroyed(this); } //clear all the effects on the unit for (int i = 0; i < effectList.Count; i++) { effectList[i].expired = true; } //call all the destroy callback, if there's any for (int i = 0; i < destroyCallbackList.Count; i++) { destroyCallbackList[i](); } //spawn the destroy effect if (showDestroyEffect) { DestroyedEffect(thisT.position + new Vector3(0, 0.1f, 0)); } if (delay > 0) { yield return(new WaitForSeconds(delay)); } //if(destroyParent) Destroy(thisT.parent.gameObject); Destroy(thisObj); yield return(null); }