korchoon
4/7/2020 - 7:11 PM

NextChild

public BezierSegment TryGetNextSegment() {
    if (IsInValidChain == false)
        return null;
    var thisIndex = transform.GetSiblingIndex();
    var isLast = thisIndex == transform.parent.childCount - 1;
    BezierSegment GetSiblingSegment(int i) => transform.parent.GetChild(i).GetComponent<BezierSegment>();
    if (isLast && BezierChain.loop)
        return GetSiblingSegment(0); // First segment
    return isLast ? null : GetSiblingSegment(thisIndex + 1);
}