Hey!
So basically I am making a car game, where I want my AI to follow a certain path. To do this I made one script for the AI and one for the path. However, for some reason the two scripts don’t seem to cooperate with eachother, and I don’t know why.
This is the script for my AI:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class NPC : MonoBehaviour
{
public GameObject destinationPoint;
NavMeshAgent theAgent;
void Start()
{
theAgent = GetComponent<NavMeshAgent>();
}
void Update()
{
theAgent.SetDestination(destinationPoint.transform.position);
}
}
This is the script for the path:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class NPC3Track : MonoBehaviour
{
public GameObject TheMarker;
public GameObject Destination1;
public GameObject Destination2;
public GameObject Destination3;
public GameObject Destination4;
public GameObject Destination5;
public GameObject Destination6;
public int MarkTracker;
void Update()
{
if (MarkTracker == 0)
{
TheMarker.transform.position = Destination1.transform.position;
}
if (MarkTracker == 1)
{
TheMarker.transform.position = Destination2.transform.position;
}
if (MarkTracker == 2)
{
TheMarker.transform.position = Destination3.transform.position;
}
if (MarkTracker == 3)
{
TheMarker.transform.position = Destination4.transform.position;
}
if (MarkTracker == 4)
{
TheMarker.transform.position = Destination5.transform.position;
}
if (MarkTracker == 5)
{
TheMarker.transform.position = Destination6.transform.position;
}
}
private IEnumerator OnTriggerEnter(Collider collision)
{
if (collision.gameObject.tag == "NPC")
{
this.GetComponent<MeshCollider>().enabled = false;
MarkTracker += 1;
if (MarkTracker == 6)
{
MarkTracker = 0;
}
}
yield return new WaitForSeconds(1);
this.GetComponent<MeshCollider>().enabled = true;
}
}