problem with ai

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);
    }
}

}

Hey @MaxPlayer2011
as I can see you have a array of points that AI can reach out when player is not in trigger zone . what you need is getting an random element from this array . so change your OnTriggerExit to this :

void OnTriggerExit(Collider other)
 {
     if (other.CompareTag("Player"))
     {
         agent.SetDestination(aiWanderPoints[Random.Range(0, aiWanderPoints.Count)].position);
     }
 }

Random.Range mthod will generate a random number for you …
let me know if your problem was solved or you have more question
Best regards
Fariborz