public void AddPartsForLevel(Transform searchTransform, Hirarchy hirarchy, int index) { int nextIndex = index; foreach (Transform childTransform in searchTransform) { if (childTransform.GetComponent <GrowingPart>()) { if (nextIndex == index) { nextIndex++; } hirarchy.AddPart(childTransform.GetComponent <GrowingPart>(), index); } AddPartsForLevel(childTransform, hirarchy, nextIndex); } }