Just add it to the ai!
using UnityEngine;
using UnityEngine.AI;
public class enemy : MonoBehaviour
{ public GameObject Player; public float Distance; public bool isAngered; public NavMeshAgent _agent; private void Start() { } private void Update() { Distance = Vector3.Distance(Player.transform.position, base.transform.position); if (Distance <= 5f) { isAngered = true; } if (Distance > 5f) { isAngered = false; } if (isAngered) { _agent.isStopped = false; } _agent.SetDestination(Player.transform.position); if (!isAngered) { _agent.isStopped = true; } } }