Ejemplo n.º 1
0
    IEnumerator Action()
    {
        while (!isDie)
        {
            yield return(ws);

            switch (state)
            {
            case State.PATROL:
                moveAgent.patrolling = true;
                animator.SetBool(hashMove, true);
                break;

            case State.TRACE:
                moveAgent.traceTarget = playerTr.position;
                animator.SetBool(hashMove, true);
                break;

            case State.ATTACK:
                moveAgent.Stop();
                animator.SetBool(hashMove, false);
                break;

            case State.DIE:
                moveAgent.Stop();
                break;
            }
        }
    }
Ejemplo n.º 2
0
    bool CheckMoveToFoe()                          // 적과의 거리 체크
    {
        if (state.isDamaging || state.isKnockDown) // 공격 받으면 잠시 멈칫한다
        {
            agent.Stop();
            return(false);
        }
        else
        {
            agent.traceTarget = playerTr.position;  // 플레이어를 쫓아간다
            Turn();

            // 일정거리 이상 다가가면 멈춘다
            float dist = (playerTr.position - transform.position).sqrMagnitude;
            if (dist <= agent.attackDistance * agent.attackDistance)
            {
                ani.OffWalk();
                ani.OnWaitB();
                return(true);
            }
            // 아니라면 계속 쫓아감
            else
            {
                ani.OffWaitB();
                ani.OnWalk();
                return(false);
            }
        }
    }
Ejemplo n.º 3
0
    private IEnumerator DoAction()
    {
        while (!isDie)
        {
            yield return(ws);

            switch (state)
            {
            case EnemyState.Patrol:
                moveAgent.isPatrol = true;
                anim.SetBool(hashMove, true);
                break;

            case EnemyState.Trace:
                moveAgent.traceTarget = playerTr.position;
                anim.SetBool(hashMove, true);
                break;

            case EnemyState.Attack:
                moveAgent.Stop();
                anim.SetBool(hashMove, false);
                break;

            case EnemyState.Die:
                moveAgent.Stop();
                break;

            default:
                break;
            }
        }
    }
Ejemplo n.º 4
0
    IEnumerator Action()
    {
        //적 캐릭터가 사망할 때까지 무한루프
        while (!isDie)
        {
            yield return(ws);

            //상태에 따라 분기 처리
            switch (state)
            {
            case State.PATROL:
                //총알 발사 정지
                EnemyFire.isFire = false;
                //순찰 모드를 활성화
                moveAgent.patroliing = true;
                animator.SetBool(hashMove, true);
                break;

            case State.TRACE:
                //총알 발사 정지
                EnemyFire.isFire = false;

                //주인공의 위치를 넘겨 추적모드로 변경
                moveAgent.traceTarget = playerTr.position;
                animator.SetBool(hashMove, true);

                break;

            case State.ATTACK:
                //순찰 및 추적을 정지
                moveAgent.Stop();
                animator.SetBool(hashMove, false);

                //총알 발사 시작
                if (EnemyFire.isFire == false)
                {
                    EnemyFire.isFire = true;
                }



                break;

            case State.DIE:
                this.gameObject.tag = "Untagged";
                isDie            = true;
                EnemyFire.isFire = false;
                //순찰 및 추적을 정리
                moveAgent.Stop();
                //사망 애니메이션의 종류를 지정
                animator.SetInteger(hashDieIdx, UnityEngine.Random.Range(0, 3));
                //사망 애니메이션 실행
                animator.SetTrigger(hashDie);
                //Capsule Collider  컴포넌트를 비활성화
                GetComponent <CapsuleCollider>().enabled = false;
                break;
            }
        }
    }
Ejemplo n.º 5
0
 //플레이어가 사망시 몬스터 올 스톱
 public void OnPlayerDie()
 {
     moveAgent.Stop();
     enemyAttack.isAttack = false;
     //모든 코루틴함수 종료
     StopAllCoroutines();
     animator.SetBool(hashMove, false);
 }
Ejemplo n.º 6
0
    public void OnPlayerDie()
    {
        moveAgent.Stop();
        enemyFire.isFire = false;

        StopAllCoroutines();

        animator.SetTrigger(hashPlayerDie);
    }
Ejemplo n.º 7
0
    IEnumerator Action()
    {
        while (!isDie)
        {
            yield return(stateCheck_time);

            switch (state)
            {
            case State.PATRAL:
                isAttack             = false;
                moveAgent.patrolling = true;
                animator.SetBool(hash_isMove, true);
                break;

            case State.TRACE:
                isAttack = false;
                moveAgent.traceTarget = playerTr.position;
                animator.SetBool(hash_isMove, true);
                break;

            case State.ATTACK:
                if (!isAttack)
                {
                    isAttack = true;
                }
                moveAgent.Stop();

                animator.SetBool(hash_isMove, false);
                break;

            case State.DIE:
                dieCount++;
                if (Quest.init.QuestIdx == 0)
                {
                    Quest.init.QuestUpdate();
                }

                isDie    = true;
                isAttack = false;
                _audio.PlayOneShot(dieSfx, 1f);
                enemyTr.Find("Cylinder").gameObject.SetActive(false);
                GameObject effect = Instantiate(dieEffect, enemyTr.position, enemyTr.rotation);
                Destroy(effect, 2f);

                moveAgent.Stop();
                animator.SetBool(hash_isDie, true);
                GetComponent <CapsuleCollider>().enabled = false;
                Destroy(gameObject, die_Delay);
                break;
            }
        }
    }
Ejemplo n.º 8
0
    //상태에 따라 적 캐릭터의 행동을 처리하는 코루틴
    IEnumerator Action()
    {
        //적 캐릭터가 사망할 때까지 무한루프
        while (!isDie)
        {
            yield return(ws);

            //상태에 따라 분기 처리
            switch (state)
            {
            case State.PATROL:
                //총알 발사 정지
                enemyFire.isFire     = false;
                moveAgent.patrolling = true;
                animator.SetBool(hashMove, true);
                break;

            case State.TRACE:
                //총알 발사 정지
                enemyFire.isFire = false;
                //주인공의 위치를 넘겨 추적 모드로 변경
                moveAgent._traecTarget = playerTr.position;
                animator.SetBool(hashMove, true);
                break;

            case State.ATTACK:
                //총알 발사 시작
                if (enemyFire.isFire == false)
                {
                    enemyFire.isFire = true;
                }
                //순찰 및 추적을 정지
                moveAgent.Stop();
                animator.SetBool(hashMove, false);
                break;

            case State.DIE:
                this.gameObject.tag = "Untagged";

                isDie            = true;
                enemyFire.isFire = false;
                //순찰 및 추적을 정지
                moveAgent.Stop();
                //사망 애니메이션의 종류를 지정
                animator.SetInteger(hashDieIdx, Random.Range(0, 3));
                //사망 애니메이션 실행
                animator.SetTrigger(hashDie);
                break;
            }
        }
    }
Ejemplo n.º 9
0
    // Use this for initialization
    IEnumerator Action()
    {
        while (!isDie)
        {
            yield return(waitSecond);

            switch (state)
            {
            case EnemyState.PATROL:
                // 순찰 모드 활성화
                enemyFire.isFire     = false;
                moveAgent.patrolling = true;
                animator.SetBool(hashMove, true);
                break;

            case EnemyState.TRACE:
                // 주인공의 위치를 넘겨 추적모드로 변경
                enemyFire.isFire      = false;
                moveAgent.traceTarget = playerTransform.position;
                animator.SetBool(hashMove, true);
                break;

            case EnemyState.ATTACK:
                if (enemyFire.isFire == false)
                {
                    enemyFire.isFire = true;
                }
                moveAgent.Stop();
                animator.SetBool(hashMove, false);
                break;

            case EnemyState.DIE:
                gameObject.tag   = "Untagged";
                isDie            = true;
                enemyFire.isFire = false;

                // 순찰 및 추적 정지
                moveAgent.Stop();

                // 사망 애니메이션 종류를 지정
                animator.SetInteger(hashDieIndex, Random.Range(0, 3));

                // 사망 트리거 전달
                animator.SetTrigger(hashDie);

                GameManager.instance.IncreaseKillCount();
                break;
            }
        }
    }
Ejemplo n.º 10
0
    IEnumerator Action() //상태에 따라 행동처리하는 코루틴
    {
        while (!isDie)   //적이 사망하기 전까지 무한루프
        {
            yield return(ws);

            switch (state) //상태에 따른 분기
            {
            case State.PATROL:
                enemyFire.isFire     = false;
                moveAgent.patrolling = true;
                animator.SetBool(hashMove, true);
                break;

            case State.TRACE:
                Find();
                enemyFire.isFire      = false;
                moveAgent.traceTarget = playerTr.position;
                animator.SetBool(hashMove, true);
                break;

            case State.ATTACK:
                moveAgent.Stop();
                animator.SetBool(hashMove, false);
                GetComponent <EnemyDamage>().getShot = false;
                if (enemyFire.isFire == false)     //총알 발사 시작
                {
                    enemyFire.isFire = true;
                }
                break;

            case State.CHASE:
                Find();
                moveAgent.traceTarget = playerTr.position;
                animator.SetBool(hashMove, true);
                break;

            case State.DIE:
                isDie            = true;
                enemyFire.isFire = false;
                moveAgent.Stop();
                audio.PlayOneShot(dieSfx);
                animator.SetInteger(hashDieIdx, UnityEngine.Random.Range(0, 3)); //사망 애니메이션 종류 지정
                animator.SetTrigger(hashDie);                                    //사망 애니메이션 실행
                GetComponent <CapsuleCollider>().enabled = false;                //충돌 판정 비활성화
                break;
            }
        }
    }
Ejemplo n.º 11
0
    // 상태에 따라 적 캐릭터의 행동을 처리하는 코루틴 함수
    IEnumerator Action()
    {
        // 적 캐릭터가 사망할 때까지 무한루프
        while (!dead)
        {
            yield return(new WaitForSeconds(0.05f));

            // 상태에 따라 분기 처리
            switch (state)
            {
            case State.Patrol:
                // 순찰 모드를 활성화
                moveAgent.patrolling = true;
                animator.SetBool("IsMove", true);
                break;

            case State.Trace:
                // 추적할 대상을 할당
                moveAgent.traceTarget = targetTr.position;
                animator.SetBool("IsMove", true);
                break;

            case State.Attack:
                // 순찰 및 추적을 정지
                moveAgent.Stop();
                animator.SetBool("IsMove", false);
                break;
            }
        }
    }
Ejemplo n.º 12
0
    IEnumerator Action()
    {
        while (!isDie)
        {
            yield return(ws);

            switch (state)
            {
            case State.PATROL:
                enemyFire.isFire     = false;
                moveAgent.patrolling = true;
                animator.SetBool(hashMove, true);
                break;

            case State.TRACE:
                enemyFire.isFire      = false;
                moveAgent.traceTarget = playerTr.position;
                animator.SetBool(hashMove, true);
                break;

            case State.ATTACK:
                moveAgent.Stop();
                animator.SetBool(hashMove, false);

                if (enemyFire.isFire == false)
                {
                    enemyFire.isFire = true;
                }
                break;

            case State.DIE:
                this.gameObject.tag = "Untagged";

                isDie            = true;
                enemyFire.isFire = false;

                moveAgent.Stop();

                animator.SetInteger(hashDieIdx, Random.Range(0, 3));
                animator.SetTrigger(hashDie);

                GetComponent <CapsuleCollider>().enabled = false;
                break;
            }
        }
    }
Ejemplo n.º 13
0
    private IEnumerator Action()
    {
        while (!_isDie)
        {
            yield return(ws);

            switch (state)
            {
            case State.PATROL:
                moveAgent.patrolling = true;
                //animator.SetBool("IsMove", true);
                animator.SetBool(hashMove, true);
                enemyFire.isFire = false;
                break;

            case State.TRACE:
                moveAgent.traceTarget = playerTr.position;
                animator.SetBool(hashMove, true);
                enemyFire.isFire = false;
                break;

            case State.ATTACK:
                moveAgent.Stop();
                animator.SetBool(hashMove, false);
                if (!enemyFire.isFire)
                {
                    enemyFire.isFire = true;
                }
                break;

            case State.DIE:
                isDie            = true;
                enemyFire.isFire = false;
                moveAgent.Stop();

                animator.SetInteger(hashDieIndex, Random.Range(0, 3));
                animator.SetTrigger(hashDie);

                GetComponent <CapsuleCollider>().enabled = false;

                StartCoroutine(Die());
                break;
            }
        }
    }
Ejemplo n.º 14
0
    IEnumerator Action()
    {
        while (!isDie)
        {
            yield return(ws);

            switch (_state)
            {
            case State.PATROL:
                _enemyFire.isFire  = false;
                mvAgent.Patrolling = true;
                _animator.SetBool(hashMove, true);
                break;

            case State.TRACE:
                _enemyFire.isFire   = false;
                mvAgent.TraceTarget = playerTr.position;
                _animator.SetBool(hashMove, true);
                break;

            case State.ATTACK:
                _enemyFire.isFire = true;
                mvAgent.Stop();
                _animator.SetBool(hashMove, false);
                break;

            case State.DIE:

                this.gameObject.tag = "Untagged";
                //StopAllCoroutines();
                isDie             = true;
                _enemyFire.isFire = false;
                mvAgent.Stop();
                _animator.SetInteger(hashDieIdx,
                                     Random.Range(0, 3));
                _animator.SetTrigger(hashDie);
                GetComponent <CapsuleCollider>().enabled = false;
                StartCoroutine(PushEnemyPool());

                break;
            }
        }
    }
Ejemplo n.º 15
0
    IEnumerator Action()
    {
        while (!isDie) // 적 캐릭터가 사망할 때 까지 무한루프
        {
            yield return(ws);

            switch (state)                    // 상태에 따라 분기 처리
            {
            case State.PATROL:                // 순찰 모드 활성화
                enemyFire.isFire     = false; // 총알 발사 정지
                moveAgent.patrolling = true;
                animator.SetBool(hashMove, true);
                break;

            case State.TRACE:                  // 주인공의 위치를 넘겨 추적 모드로 변경
                enemyFire.isFire      = false; // 총알 발사 정지
                moveAgent.traceTarget = playerTr.position;
                animator.SetBool(hashMove, true);
                break;

            case State.ATTACK:     // 순찰 및 추적을 정지
                moveAgent.Stop();
                animator.SetBool(hashMove, false);
                if (enemyFire.isFire == false)     // 총알 발사 시작
                {
                    enemyFire.isFire = true;
                }
                break;

            case State.DIE:
                isDie            = true;
                enemyFire.isFire = false;                            // 순찰 및 추적을 정지
                moveAgent.Stop();
                animator.SetInteger(hashDieIdx, Random.Range(0, 3)); // 사망 애니메이션의 종류를 지정
                animator.SetTrigger(hashDie);
                GetComponent <CapsuleCollider>().enabled = false;    // Capsule Collider 컴포넌트 비활성화

                break;
            }
        }
    }
Ejemplo n.º 16
0
    IEnumerator Action()
    {
        while (!isDie)
        {
            yield return(ws);

            switch (state)
            {
            case STATE.STATE_PATROL:
                enemyFire.isFire     = false;
                moveagent.patrolling = true;
                animator.SetBool(hashMove, true);
                break;

            case STATE.STATE_TRACE:
                enemyFire.isFire      = false;
                moveagent.traceTarget = playerTr.position;
                animator.SetBool(hashMove, true);
                break;

            case STATE.STATE_ATTACK:
                moveagent.Stop();
                animator.SetBool(hashMove, false);
                if (enemyFire.isFire == false)
                {
                    enemyFire.isFire = true;
                }
                break;

            case STATE.STATE_DIE:
                isDie = true;
                playerLv.KillEnemy();
                enemyFire.isFire = false;
                moveagent.Stop();
                animator.SetInteger(hashDieIdx, Random.Range(0, 3));
                animator.SetTrigger(hashDie);
                GetComponent <CapsuleCollider>().enabled = false;
                break;
            }
        }
    }
Ejemplo n.º 17
0
    //상태를 보고 행동을 변화하게 하는 코루틴을 추가하자.
    IEnumerator Action()
    {
        while (!_isDie)
        {
            yield return(ws);

            switch (state)
            {
            case State.ATTACK:
                moveAgent.Stop();
                animator.SetBool(hashFind, true);

                enemyAttack.isAttack = true;
                break;

            case State.DIE:

                break;

            case State.IDLE:

                break;

            case State.PATROL:
                animator.SetBool(hashWalk, false);
                moveAgent.patrolling = true;
                break;

            case State.TRACE:
                animator.SetBool(hashWalk, true);

                moveAgent.traceTarget = playerTrans.position;
                break;
            }
        }
    }
Ejemplo n.º 18
0
    IEnumerator Action()
    {
        while (!isDie)
        {
            yield return(null);

            switch (m_CurrentState)
            {
            case State.Idle:
                myAni.ChangeAni(MonsterAni.IDLE);
                break;

            case State.Chase:
                if (BattleSceneManager.getInstance().CharacterCount == 3)
                {
                    if (MinDistancePlayer == GetDistanceFromPlayer()[0])
                    {
                        // attack_flag = 1;
                        moveAgent.TraceTarget = player[0].transform.position;
                        //Debug.Log("1번 캐릭터감지");
                    }
                    if (MinDistancePlayer == GetDistanceFromPlayer()[1])
                    {
                        //attack_flag = 2;
                        moveAgent.TraceTarget = player[1].transform.position;
                        //Debug.Log("2번 캐릭터감지");
                    }
                    if (MinDistancePlayer == GetDistanceFromPlayer()[2])
                    {
                        //attack_flag = 3;
                        moveAgent.TraceTarget = player[2].transform.position;
                        //Debug.Log("3번 캐릭터감지");
                    }
                }
                if (BattleSceneManager.getInstance().CharacterCount == 2)
                {
                    //if (MinDistancePlayer == GetDistanceFromPlayer2()[0])
                    //{
                    //    attack_flag = 1;
                    //    moveAgent.TraceTarget = player[0].transform.position;

                    //}
                    //if (MinDistancePlayer == GetDistanceFromPlayer2()[1])
                    //{
                    //    attack_flag = 2;
                    //    moveAgent.TraceTarget = player[1].transform.position;
                    //    //Debug.Log("2번 캐릭터감지");
                    //}

                    if (MinDistancePlayer == GetDistanceFromPlayer2()[0])
                    {
                        //attack_flag = 1;
                        if (player[0] == null)
                        {
                            moveAgent.TraceTarget = player[1].transform.position;
                        }
                        else
                        {
                            moveAgent.TraceTarget = player[0].transform.position;
                        }
                    }
                    if (MinDistancePlayer == GetDistanceFromPlayer2()[1])
                    {
                        //attack_flag = 2;
                        if (player[1] == null)
                        {
                            moveAgent.TraceTarget = player[2].transform.position;
                        }
                        else
                        {
                            moveAgent.TraceTarget = player[1].transform.position;
                        }
                        //Debug.Log("2번 캐릭터감지");
                    }
                }
                if (BattleSceneManager.getInstance().CharacterCount == 1)
                {
                    if (MinDistancePlayer == GetDistanceFromPlayer3()[0])
                    {
                        // attack_flag = 1;
                        if (player[0] != null)
                        {
                            moveAgent.TraceTarget = player[0].transform.position;
                        }
                        if (player[1] != null)
                        {
                            moveAgent.TraceTarget = player[1].transform.position;
                        }
                        if (player[2] != null)
                        {
                            moveAgent.TraceTarget = player[2].transform.position;
                        }
                    }
                }
                myAni.ChangeAni(MonsterAni.WALK);
                break;

            case State.Attack:
                moveAgent.Stop();
                if (BattleSceneManager.getInstance().CharacterCount == 3)
                {
                    if (MinDistancePlayer == GetDistanceFromPlayer()[0])
                    {
                        attack_flag = 1;
                        Quaternion rot = Quaternion.LookRotation(player[0].transform.position - cachedTransform.position);
                        cachedTransform.rotation = Quaternion.Slerp(cachedTransform.rotation, rot, Time.deltaTime * 360f);
                    }
                    if (MinDistancePlayer == GetDistanceFromPlayer()[1])
                    {
                        attack_flag = 2;
                        Quaternion rot = Quaternion.LookRotation(player[1].transform.position - cachedTransform.position);
                        cachedTransform.rotation = Quaternion.Slerp(cachedTransform.rotation, rot, Time.deltaTime * 360f);
                    }
                    if (MinDistancePlayer == GetDistanceFromPlayer()[2])
                    {
                        attack_flag = 3;
                        Quaternion rot = Quaternion.LookRotation(player[2].transform.position - cachedTransform.position);
                        cachedTransform.rotation = Quaternion.Slerp(cachedTransform.rotation, rot, Time.deltaTime * 360f);
                    }
                }
                if (BattleSceneManager.getInstance().CharacterCount == 2)
                {
                    //if (player[0].GetComponent<PlayerState>().m_CurrentState == PlayerState.State.Dead)
                    //{
                    //    myAni.ChangeAni(MonsterAni.IDLE);
                    //    m_CurrentState = State.Idle;
                    //}
                    if (MinDistancePlayer == GetDistanceFromPlayer2()[0])
                    {
                        attack_flag = 1;
                        if (player[2] == null)
                        {
                            Quaternion rot = Quaternion.LookRotation(player[0].transform.position - cachedTransform.position);
                            cachedTransform.rotation = Quaternion.Slerp(cachedTransform.rotation, rot, Time.deltaTime * 360f);
                        }
                        if (player[1] == null)
                        {
                            Quaternion rot = Quaternion.LookRotation(player[0].transform.position - cachedTransform.position);
                            cachedTransform.rotation = Quaternion.Slerp(cachedTransform.rotation, rot, Time.deltaTime * 360f);
                        }
                        if (player[0] == null)
                        {
                            Quaternion rot = Quaternion.LookRotation(player[1].transform.position - cachedTransform.position);
                            cachedTransform.rotation = Quaternion.Slerp(cachedTransform.rotation, rot, Time.deltaTime * 360f);
                        }
                    }
                    if (MinDistancePlayer == GetDistanceFromPlayer2()[1])
                    {
                        attack_flag = 2;
                        if (player[2] == null)
                        {
                            Quaternion rot = Quaternion.LookRotation(player[1].transform.position - cachedTransform.position);
                            cachedTransform.rotation = Quaternion.Slerp(cachedTransform.rotation, rot, Time.deltaTime * 360f);
                        }
                        if (player[1] == null)
                        {
                            Quaternion rot = Quaternion.LookRotation(player[2].transform.position - cachedTransform.position);
                            cachedTransform.rotation = Quaternion.Slerp(cachedTransform.rotation, rot, Time.deltaTime * 360f);
                        }
                        if (player[0] == null)
                        {
                            Quaternion rot = Quaternion.LookRotation(player[2].transform.position - cachedTransform.position);
                            cachedTransform.rotation = Quaternion.Slerp(cachedTransform.rotation, rot, Time.deltaTime * 360f);
                        }
                    }
                }
                if (BattleSceneManager.getInstance().CharacterCount == 1)
                {
                    if (MinDistancePlayer == GetDistanceFromPlayer3()[0])
                    {
                        attack_flag = 1;
                        if (player[0] != null)
                        {
                            Quaternion rot = Quaternion.LookRotation(player[0].transform.position - cachedTransform.position);
                            cachedTransform.rotation = Quaternion.Slerp(cachedTransform.rotation, rot, Time.deltaTime * 360f);
                        }
                        if (player[1] != null)
                        {
                            Quaternion rot = Quaternion.LookRotation(player[1].transform.position - cachedTransform.position);
                            cachedTransform.rotation = Quaternion.Slerp(cachedTransform.rotation, rot, Time.deltaTime * 360f);
                        }
                        if (player[2] != null)
                        {
                            Quaternion rot = Quaternion.LookRotation(player[2].transform.position - cachedTransform.position);
                            cachedTransform.rotation = Quaternion.Slerp(cachedTransform.rotation, rot, Time.deltaTime * 360f);
                        }
                    }
                }
                if (attackstate == true)
                {
                    myAni.ChangeAni(MonsterAni.ATTACK);
                }
                break;

            case State.NoState:

                break;

            case State.Dead:
                isDie = true;
                moveAgent.Stop();
                myAni.ChangeAni(MonsterAni.DIE);
                GetComponent <SphereCollider>().enabled = false;
                //myParams.isDead = true;
                break;
            }
        }
    }
Ejemplo n.º 19
0
    IEnumerator Action()
    {
        while (!isDead)
        {
            yield return(waitSeconds);

            switch (state)
            {
            case EnemyState.IDLE:
                ea.isFire            = false;
                moveAgent.patrolling = false;
                ani.SetBool(hashMove, false);
                break;

            case EnemyState.PATROL:
                ea.isFire            = false;
                moveAgent.patrolling = true;
                GetComponent <Collider>().enabled = true;
                ani.SetBool(hashMove, true);
                ani.SetBool(hashDown, false);
                break;

            case EnemyState.TRACE:
                ea.isFire            = false;
                moveAgent.patrolling = false;
                WatchingPlayer();
                moveAgent.traceTarget = playerLastPos;
                ani.SetBool(hashMove, true);
                break;

            case EnemyState.DIE:
                moveAgent.Stop();
                isDead = true;
                ani.SetBool(hashMove, false);
                ani.SetBool(hashDown, true);
                break;

            case EnemyState.SEARCH:
                ea.isFire = false;
                float elapsedTime = 0.0f;
                while (!WatchingPlayer())
                {
                    elapsedTime += Time.deltaTime;
                    moveAgent.Stop();
                    ani.SetBool(hashMove, false);
                    if (elapsedTime <= 2.0f)
                    {
                        transform.rotation = Quaternion.Euler(0, 90, 0);
                    }
                    else if (elapsedTime <= 4.0f)
                    {
                        transform.rotation = Quaternion.Euler(0, -90, 0);
                    }
                    else
                    {
                        transform.rotation        = Quaternion.identity;
                        moveAgent.agent.isStopped = true;
                        state = EnemyState.PATROL;
                        break;
                    }
                    yield return(null);
                }
                break;

            case EnemyState.UNARMED:
                if (!isDown && !isArmed)
                {
                    SearchWeapon();
                }
                break;

            case EnemyState.KNOCKDOWN:
                moveAgent.Stop();
                ea.isFire = false;
                isDown    = true;
                GetComponent <Collider>().enabled = false;
                ani.SetBool(hashMove, false);
                ani.SetBool(hashDown, true);

                float knockDownTime = 0.0f;
                while (knockDownTime <= 3.0f)
                {
                    if (state == EnemyState.DIE)
                    {
                        break;
                    }

                    knockDownTime += Time.deltaTime;
                    yield return(null);
                }

                if (state != EnemyState.DIE)
                {
                    isDown = false;
                }
                break;

            case EnemyState.CHICKEN:
                ani.SetBool(hashMove, false);
                Quaternion rot = Quaternion.LookRotation(player.transform.position);
                transform.rotation = Quaternion.Slerp(transform.rotation, rot, 5.0f);
                break;

            case EnemyState.FIRE:
                yield return(new WaitForSeconds(0.2f));

                if (ea.isFire == false)
                {
                    ea.isFire = true;
                }
                moveAgent.Stop();
                ani.SetBool(hashMove, false);
                break;
            }
        }
        yield break;
    }
Ejemplo n.º 20
0
    IEnumerator Action()
    {
        while (!isDie)
        {
            yield return(wSecond);

            barricadeList = bManager.obstacleList;
            float distance       = Vector3.Distance(playerTr.position, enemyTr.position);
            float bcListDistance = 0.0f;
            if (barricadeList.Count > 0)
            {
                if (barricadeList.Count > 1)
                {
                    for (int i = 0; i < barricadeList.Count; i++)
                    {
                        if (i == 0)
                        {
                            compare = barricadeList[i];
                        }
                        else
                        {
                            if (Vector3.Distance(compare.position, enemyTr.position) > Vector3.Distance(barricadeList[i].position, enemyTr.position))
                            {
                                compare = barricadeList[i];
                            }
                        }
                        bListTr = compare;
                    }
                }
                else if (barricadeList.Count == 1)
                {
                    bListTr = barricadeList[0];
                }
                bcListDistance = Vector3.Distance(enemyTr.position, bListTr.position);
            }
            switch (state)
            {
            case STATE.IDLE:
                erAttack.isFire = false;
                animator.SetInteger("Condition", 0);
                moveAgent.ideling = true;
                break;

            case STATE.TRACE:
                erAttack.isFire = false;
                if (distance < bcListDistance || bListTr == null)
                {
                    animator.SetInteger("Condition", 1);
                    moveAgent.traceTarget = playerTr.position;
                }
                else if (bcListDistance < distance)
                {
                    moveAgent.traceTarget = bListTr.position;
                }
                break;

            case STATE.ATTACK:
                moveAgent.Stop();
                if (erAttack.isFire == false)
                {
                    erAttack.isFire = true;
                }
                if (bListTr == null)
                {
                    moveAgent.traceTarget = playerTr.position;
                }
                if (bListTr != null && moveAgent.traceTarget != bListTr.position && moveAgent.traceTarget != playerTr.position)
                {
                    moveAgent.traceTarget = playerTr.position;
                }
                if (bListTr != null && moveAgent.traceTarget == bListTr.position && distance <= attackDist)
                {
                    moveAgent.traceTarget = playerTr.position;
                }
                if (bListTr != null && moveAgent.traceTarget == playerTr.position && bcListDistance < distance && distance > attackDist && bListTr.GetComponent <RepairManager>().isSelected == false)
                {
                    moveAgent.traceTarget = bListTr.position;
                }
                if (bListTr != null && bListTr.GetComponent <RepairManager>().wallHealth <= 0)
                {
                    state = STATE.TRACE;
                }
                break;

            case STATE.DIE:
                animator.SetInteger("Condition", 4);
                moveAgent.Stop();
                break;
            }
        }
    }