Alright I have a list of Transforms which are locations that I want my NPC to travel. What I want is onTriggerEnter (which is in a different script) the NPC needs to move to the first array in said list. I have print statements throughout my script showing that all the areas are being called correctly but my NPC still continues to move about through the entire list instead of just that one spot. Any ideas on how to get it to stop moving through the list, other than what I have because it is not working. The setup has a box collider in the area where the NPC is. So the trigger is just when the player gets close to the NPC. Heres the code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class Moveto : MonoBehaviour
{
//these are the spots the NPCs will go
public List<Transform> goal;
public Transform MC;
private NavMeshAgent agent;
private bool talkTo;
private int count;
// Start is called before the first frame update
void Start()
{
agent = GetComponent<NavMeshAgent>();
count = 0;
talkTo = false;
}
public void move(bool talk)
{
print(talk);
if(talk)
{
float speed = 1f * Time.deltaTime;
agent.destination = Vector3.MoveTowards(goal[count].position, goal[0].position, speed);
}
else{
agent.destination = goal[count].position;
}
count++;
if(count == 3)
count = 0;
}
// Update is called once per frame
void Update()
{
//check to see if the MC is talking to NPC
if(talkTo == false){
//check to see if destination is reached
if(!agent.pathPending)
{
if(agent.remainingDistance <= agent.stoppingDistance)
{
if (!agent.hasPath || agent.velocity.sqrMagnitude == 0f)
{
move(false);
}
}
}
}
else{
print("in else statement");
move(true);
}
}
public void moveToMC(bool willTalk)
{
print("made it to moveToMC function" + willTalk);
talkTo = willTalk;
}
}