So I have a WIP script that is a simple AI that follows the player when sees it, and then when she doesn’t chase you she will walk around randomly. The problem is that I created public transform aiWanderPoints and now I don’t know how to choose a random element. Here’s my script:
using UnityEngine;
using UnityEngine.AI;
public class AI : MonoBehaviour
{
public Transform Player;
private NavMeshAgent agent;
public Transform aiWanderPoints;
void Start()
{
agent = GetComponent<NavMeshAgent>();
}
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
agent.SetDestination(Player.position);
}
}
void OnTriggerExit(Collider other)
{
if (other.CompareTag("Player"))
{
agent.SetDestination(aiWanderPoints[].position);
}
}
}