Beispiel #1
0
        protected override AiAction GetCurrentState()
        {
            if (!_isNear)
            {
                return(_patrolAi);
            }
            float dist;

            if (CurrentState == _patrolAi)
            {
                var pathFound = NavMesh.CalculatePath(transform.position, TargetTransform.position, NavMesh.AllAreas,
                                                      _pathToTarget);
                if (!pathFound)
                {
                    return(_patrolAi);
                }
                dist = NavUtils.GetPathLength(_pathToTarget);
            }
            else
            {
                dist = _navMeshAgent.remainingDistance;
            }

            if (dist <= AttackDistance)
            {
                return(_attackAi);
            }
            return(_patrolAi);
        }
 protected override AiAction GetCurrentState()
 {
     foreach (var enemy in Enemies)
     {
         var pathFound = NavMesh.CalculatePath(enemy.position, PlayerTransform.position, NavMesh.AllAreas, _navMeshPath);
         if (!pathFound || NavUtils.GetPathLength(_navMeshPath) > AttackDistance)
         {
             continue;
         }
         _attackAi.TargetTransform = enemy;
         return(_attackAi);
     }
     return(_followAi);
 }