示例#1
0
    IEnumerator CheckState()
    {
        while (!isDie)
        {
            if (state == EnemyState.DIE)
            {
                yield break;
            }

            // 주인공과 적 캐릭터의 사이의 거리를 계산
            //float dist = Vector3.Distance(playerTransform.position, transform.position);            // 실수연산을 하므로 CPU에 부하가 심하다 따라서 sqrMagnitude를 이용하여 제곱수를 사용한다.
            float dist = (playerTransform.position - transform.position).sqrMagnitude;

            if (dist <= attackDistance * attackDistance)
            {
                Vector3 startPosition = new Vector3(
                    transform.position.x,
                    transform.position.y + enemyFire.firePos.position.y,
                    transform.position.z);
                if (enemyFOV.IsViewPlayer())
                {
                    state = EnemyState.ATTACK;
                }
            }
            else if (enemyFOV.IsTracePlayer())
            {
                state = EnemyState.TRACE;
            }
            else
            {
                state = EnemyState.PATROL;
            }
            yield return(waitSecond);
        }
    }
示例#2
0
    IEnumerator CheckState()
    {
        while (!isDie)
        {
            if (state == State.DIE)
            {
                yield break;
            }

            float dist = Vector3.Distance(playerTr.position, enemyTr.position);

            if (dist <= attackDist)
            {
                if (enemyFOV.IsViewPlayer())
                {
                    state = State.ATTACK;
                }
                else
                {
                    state = State.TRACE;
                }
            }
            else if (enemyFOV.IsTracePlayer())
            {
                state = State.TRACE;
            }
            else
            {
                state = State.PATROL;
            }

            yield return(ws);
        }
    }
示例#3
0
 private void CheckState()
 {
     if (enemyFOV.IsTracePlayer() && !isTargeting)       //어그로 안끌린상태
     {
         if (enemyFOV.IsViewPlayer())
         {
             targetPoint = enemyFOV.targetPos;
             isTargeting = true;
         }
     }
     else if (enemyFOV.IsTracePlayer() && isTargeting)       //어그로 끌린상태
     {
         state = State.TRACE;
         //공격 거리 체크
     }
     else if (!enemyFOV.IsTracePlayer())     //원안에 안들어가있는 상태
     {
         isTargeting = false;
         state       = State.PATROL;
     }
 }
示例#4
0
    protected virtual void CheckState()
    {
        if (currentState == State.Hit || currentState == State.Dead || currentState == State.Stun)
        {
            return;
        }

        bool isTrace  = fov.IsTracePlayer();
        bool isView   = fov.IsViewPlayer();
        bool isAttack = fov.IsAttackPossible();

        if (isAttack && isView && isTrace)
        {
            currentState = State.Attack;
        }
        else if (isTrace && isView)
        {
            currentState = State.Chase;
        }
        else
        {
            currentState = State.Patrol;
        }
    }