public class AgentBehaviour : MonoBehaviour
{
private NavMeshAgent _navMeshAgent;
public Spawn agent;
public GameObject goals;
void Start()
{
agent = GetComponent<Spawn>();
_navMeshAgent = GetComponent<NavMeshAgent>();
SetGoal();
}
// Update is called once per frame
void Update()
{
}
void SetGoal()
{
_navMeshAgent.SetDestination(goals[Random.Range(0, 5)].transform.position);
}
}
I’m trying to assign random positions(from list of 5 objects) for my agents to go there.
Each value(typed or drawn) results in “IndexOutOfRangeException:Index was outside the bounds of the array” in line _navMeshAgent.SetDestination(goals[Random.Range(0, 5)].transform.position); . Anyone has any ideas?