Transform[] drawns = GetComponentsInChildren<Transform>()
This include also the parent but i want to get only the children of the transform the script is connected.
The problem is that it's destroying in the loop also the parent. The first item in the array of drawns is the parent :
case DrawStates.DrawOnGizmosRuntime:
drawOnce = true;
if (line != null && drawOnGizmos == false)
{
Transform[] drawns = GetComponentsInChildren<Transform>();
if (drawns.Length > 0)
{
foreach (Transform drawn in drawns)
{
Destroy(drawn.gameObject);
}
}
}
if (boxCollider == null)
{
boxCollider = boxColliderToDrawOn.GetComponent<BoxCollider>();
}
drawOnGizmos = true;
break;