Hi, it seems so early to have an error in the code. But i am getting and Index Out of Range Error.

I am not sure why anyone else had the same?

using System;
using System.Collections.Generic;
using UnityEngine;
using System.Collections;

public class PathDefintion : MonoBehaviour
{
public Transform[] Points;
public IEnumerator<Transform> GetPathEnumerator()
{
if (Points == null || Points.Length < 1)
yield break;

var direction = 1;
var index = 0;

while (true)
{

Debug.Log("Index is" + index);

yield return Points[index];

if (Points.Length == 1)
continue;

if (index <= 0)
direction = 1;
else if (index >= Points.Length - 1)
direction = 1;
index = index + direction;
}
}

public void OnDrawGizmos()
{
if (Points == null || Points.Length < 2)
return;

for (var i = 1; i < Points.Length; i++)
{
Gizmos.DrawLine(Points[i - 1].position, Points[i].position);
}
}

}