Question about waypoints

Hi.
I have an object that follows a waypoints, my question is
How can I make the object look for a different waypoint when it reaches the end?

my code is :

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

public class MovimientoCarril : MonoBehaviour
{
//this is the path
public Carril1 PathFollow;

public int CurrentWaypointID = 0;
public float speed;
private float reachDistance = 1.0f;

Vector3 last_position;

void Start()
{

last_position = transform.position;

}

void Update()
{

float distance = Vector3.Distance(PathFollow.path_objs[CurrentWaypointID].position, transform.position);
transform.position = Vector3.MoveTowards(transform.position, PathFollow.path_objs[CurrentWaypointID].position, Time.deltaTime * speed);

if (distance <= reachDistance)
{
CurrentWaypointID++;
}
}

}

First use the code tags when inputting code into the post.

Why not just loop your way-points? Once the object reaches the last waypoint, it will go to the first.

Something like:

if (distance <= reachDistance)
{

if(++CurrentWapoint == lastWaypoint)
CurrentWapoint  = 0;
}

You may have to mess around with the prefix vs post-fix “++” increment, But should work.

curWaypointIndex = (curWaypointIndex + 1) % waypoints.length;