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++;
}
}
}