public NavMeshAgent navMeshAgent;
public Transform player;
public Transform[] points;
void Start(){
navMeshAgent = GetComponent<NavMeshAgent>();
navMeshAgent.SetDestination(points[0].position)
}
void Update(){
CheckPlayerOnRoom();
if (navMeshAgent.remainingDistance < 1f){
var inx = Array.IndexOf(points, points.FirstOrDefault(e => e.position == navMeshAgent.destination));
if(inx != -1)
navMeshAgent.SetDestination(points[(inx+1)% points.Length].position);
}
}
void CheckPlayerOnRoom(){
if (Check.playerOnRoom && door.transform.rotation == Quaternion.Euler(0, -90, 0) && Array.IndexOf(points, points.FirstOrDefault(e => e.position == navMeshAgent.destination) == 0)
navMeshAgent.SetDestination(points[1].position);
else
navMeshAgent.SetDestination(player.transform.position);
}
2. нет