Пример #1
0
    void ChangeState(ZOMBIE_STATE newState)
    {
        //Debug.Log("new state " + newState);
        //if (state == newState)
        //    return;

        switch (newState)
        {
        case ZOMBIE_STATE.IDLE:
            _navMeshAgent.isStopped = true;
            currAnimName            = "idle";
            this.GetComponent <Animator>().Play(currAnimName, 0);
            break;

        case ZOMBIE_STATE.WALK:
            //_navMeshAgent.SetDestination(player.transform.position);
            _navMeshAgent.isStopped = false;
            currAnimName            = "w" + moveAnimID.ToString();
            this.GetComponent <Animator>().Play(currAnimName, 0);
            break;

        case ZOMBIE_STATE.SCREAM:
            _navMeshAgent.isStopped = true;
            currAnimName            = "scream1";
            this.GetComponent <Animator>().Play(currAnimName, 0);
            break;

        case ZOMBIE_STATE.ATTACK:
            _navMeshAgent.isStopped = true;
            currAnimName            = "a" + attackAnimID.ToString();
            this.GetComponent <Animator>().Play(currAnimName, 0);
            break;

        case ZOMBIE_STATE.DIE:
            state = ZOMBIE_STATE.DIE;
            _navMeshAgent.isStopped = true;
            dead = true;
            //delete the collider
            if (GetComponent <CapsuleCollider>())
            {
                Destroy(GetComponent <CapsuleCollider>());
            }
            _navMeshAgent.isStopped = true;
            if (GetComponent <Rigidbody>())
            {
                Destroy(GetComponent <Rigidbody>());
            }
            Death();
            break;

        case ZOMBIE_STATE._COUNT:
        default:
            break;
        }

        state = newState;
    }
Пример #2
0
    private string currAnimName;//read only use

    protected void Start()
    {
        player = GameObject.FindGameObjectWithTag("Player");

        state        = ZOMBIE_STATE.IDLE;
        attackAnimID = Random.Range(0, 2) + 1;
        moveAnimID   = Random.Range(0, 4) + 1;
        deathAnimID  = Random.Range(0, 2) + 1;

        moveSpeed = moveAnimID * 0.44f;
        timer     = timeToScream = 0;
        RandomizeTimeToScream();

        dead      = false;
        attacking = false;

        _navMeshAgent.speed = moveSpeed;
    }
Пример #3
0
    public void ChangeState(ZOMBIE_STATE state)
    {
        // Stop all AI Processing
        StopAllCoroutines();

        // set new state
        activeState = state;

        switch (activeState)
        {
        case ZOMBIE_STATE.PATROL:
            StartCoroutine(AIPatrol());
            return;

        case ZOMBIE_STATE.CHASE:
            StartCoroutine(AIChase());
            // Broadcast this event maybe, like play warning sound
            return;

        case ZOMBIE_STATE.ATTACK:
            StartCoroutine(AIAttack());
            return;
        }
    }
Пример #4
0
    public override void RunFSM()
    {
        GameObject m_TargetedEnemy = TargetToAttack();

        switch (zombieState)
        {
        case ZOMBIE_STATE.Z_IDLE:

            if (GetClosestDestination() != null)
            {
                zombieState = ZOMBIE_STATE.Z_CHASE;
            }

            if (this.HP <= 0)
            {
                zombieState = ZOMBIE_STATE.Z_DEAD;
            }

            break;

        case ZOMBIE_STATE.Z_CHASE:

            if (this.HP <= 0)
            {
                zombieState = ZOMBIE_STATE.Z_DEAD;
            }

            if (m_TargetedEnemy == null && GetClosestDestination() != null)
            {
                GameObject targetToChase = GetClosestDestination();
                // Translate
                Vector3 dir = (targetToChase.transform.position - this.gameObject.transform.position).normalized;
                dir.y = 0;
                this.gameObject.transform.position += dir * moveSpd * Time.deltaTime;

                // Rotate
                Quaternion lookRotation = Quaternion.LookRotation(dir);
                transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, Time.deltaTime);
            }
            else if (GetClosestDestination() == null)
            {
                zombieState = ZOMBIE_STATE.Z_IDLE;
            }
            else
            {
                zombieState = ZOMBIE_STATE.Z_ATTACK;
            }


            break;

        case ZOMBIE_STATE.Z_ATTACK:

            if (this.HP <= 0)
            {
                zombieState = ZOMBIE_STATE.Z_DEAD;
            }

            if (m_TargetedEnemy != null)
            {
                AttackEnemy(m_TargetedEnemy);
            }
            else
            {
                zombieState = ZOMBIE_STATE.Z_CHASE;
            }

            break;

        case ZOMBIE_STATE.Z_DEAD:
            Destroy(this.gameObject);
            break;
        }
    }