void GetNextWaypoint() { //Reset path if reached end if (!back) { if (pathnodeid >= path.points.Length - 1) { if (path.GetRepeat()) { back = true; return; } pathnodeid = 0; target = path.points[pathnodeid]; return; } } if (!back) { pathnodeid++; } else { pathnodeid--; } if (back && pathnodeid == 0) { pathnodeid = 0; back = false; } target = path.points[pathnodeid]; }