示例#1
0
    private void PatrolBehavior( )
    {
        Vector3 nextPosition = guardPosition;

        if (beingAttracted && Vector3.Distance(transform.position, coinPos) <= 5f)
        {
            _navMeshAgent.isStopped = true;
            _animator.SetBool(IsWalking, false);
            StartCoroutine(InvestigateCoin( ));
        }

        if (_patrolPath is null || beingAttracted)
        {
            return;
        }

        if (AtWaypoint( ))
        {
            timeSinceArrivedWaypoint = 0f;
            _animator.SetBool(IsWalking, false);
            pauseAtWaypoint = _patrolPath.GetPauseAtWaypoint(currentWaypointIndex);
            CycleWaypoint( );
            randRange = Random.Range(2f, 5f);
        }

        nextPosition = GetCurrentWaypoint( );

        if (!pauseAtWaypoint || timeSinceArrivedWaypoint > randRange)
        {
            _navMeshAgent.destination = nextPosition;
            _navMeshAgent.speed       = patrolSpeed;
            _navMeshAgent.isStopped   = false;
            _animator.SetBool(IsWalking, true);
        }
    }