using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TrackWaypoint : MonoBehaviour
{
// AI car
public Collider[] aiCars;
// waypoints
public Transform[] waypoints;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
MoveToNextWaypoint();
}
private void OnTriggerEnter(Collider aiCars)
{
if (aiCars.gameObject.tag == "AICar")
{
MoveToNextWaypoint();
}
}
public void MoveToNextWaypoint()
{
foreach (Collider aiCarColliders in aiCars)
{
if (aiCarColliders.transform.position == waypoints[0].transform.position)
{
aiCarColliders.transform.position = waypoints[1].transform.position;
}
if (aiCarColliders.transform.position == waypoints[1].transform.position)
{
aiCarColliders.transform.position = waypoints[2].transform.position;
}
}
}
}