IEnumerator NavigationLine(float waitTime) { while (true) { yield return(new WaitForSeconds(waitTime)); //CurvySpline curvySpline = pathEnhanced.GetComponent<CurvySpline>(); segmentsToSearch.Add(curSegment); if (curSegment.SegmentIndex != curvySpline.Segments.Count - 1 && curSegment.SegmentIndex != 0) { segmentsToSearch.Add(curvySpline[curSegment.SegmentIndex + 1].GetComponent <CurvySplineSegment>()); segmentsToSearch.Add(curvySpline[curSegment.SegmentIndex - 1].GetComponent <CurvySplineSegment>()); } else if (curSegment.SegmentIndex == curvySpline.Segments.Count - 1) { segmentsToSearch.Add(curvySpline[0].GetComponent <CurvySplineSegment>()); } else if (curSegment.SegmentIndex == 0) { segmentsToSearch.Add(curvySpline[1].GetComponent <CurvySplineSegment>()); } float carTf = curvySpline.GetNearestPointTFExt(transform.position, segmentsToSearch.ToArray()); linesUtilsAlt.DrawLine(gameObject, curvySpline, carTf); curSegment = curvySpline.TFToSegment(carTf); segmentsToSearch.Clear(); //else if (linesUtilsAlt.LineRend.positionCount != 0) // linesUtilsAlt.LineRend.positionCount = 0; //delete the LineRenderer } }