решено вот код(лишнее убрал):
public NavMeshAgent navMeshAgent;
public Transform player;
public Transform[] points;
[SerializeField] private int currentPoint;
void Start()
{
currentPoint = 0;
navMeshAgent = GetComponent<NavMeshAgent>();
}
void Update()
{
CheckPlayerOnRoom();
if (navMeshAgent.remainingDistance < 1f)
{
currentPoint += 1;
if (currentPoint >= points.Length) currentPoint = 0;
navMeshAgent.SetDestination(points[currentPoint].position);
}
}
void CheckPlayerOnRoom()
{
if (Check.playerOnRoom && door.transform.rotation == Quaternion.Euler(0, -90, 0))
{
if(currentPoint == 0) navMeshAgent.SetDestination(points[1].position);
}
else
{
currentPoint = 0;
navMeshAgent.SetDestination(player.transform.position);
}
}