コード例 #1
0
    void Move()
    {
        _animator.SetTrigger("b_IsMoving");
        isMoving = true;
        Vector3 offset = destination - transform.position;

        offset.y = 0;
        if (offset.sqrMagnitude < 0.05 * 0.05)
        {
            EUS      = EnemyUnitState.EUS_IDLE;
            isMoving = false;
            //_navMeshAgent.ResetPath();
        }
        else
        {
            //transform.position += offset.normalized * Time.deltaTime * f_speed;
            _navMeshAgent.SetDestination(destination);
            LookDirection();
        }

        GameObject tempPlayer = DetectPlayerUnit();

        if (tempPlayer != null)
        {
            if ((tempPlayer.transform.position - transform.position).sqrMagnitude <= f_range * f_range)
            {
                go_LockOnUnit = tempPlayer;
                EUS           = EnemyUnitState.EUS_CHASE;
            }
        }
    }
コード例 #2
0
    void Defend()
    {
        _navMeshAgent.SetDestination(destination);
        LookDirection();
        Vector3 difference = destination - transform.position;

        //transform.position += difference.normalized * Time.deltaTime * f_speed;
        if (difference.sqrMagnitude < 0.1f * 0.1f)
        {
            EUS = EnemyUnitState.EUS_IDLE;
            _navMeshAgent.ResetPath();
        }
    }
コード例 #3
0
    void Chase()
    {
        if (go_LockOnUnit != null)
        {
            _animator.SetTrigger("b_IsMoving");
            _animator.ResetTrigger("b_IsAttacking");
            Vector3 difference = go_LockOnUnit.transform.position - transform.position;

            if (difference.sqrMagnitude < f_atkRange * f_atkRange)
            {
                EUS = EnemyUnitState.EUS_ATTACK;
                _navMeshAgent.ResetPath();
            }
            else if (difference.sqrMagnitude > f_range * f_range || ((transform.position - destination).sqrMagnitude > f_defendRange * f_defendRange && isDefending))
            {
                if (isDefending)
                {
                    EUS = EnemyUnitState.EUS_DEFEND;
                }
                else
                {
                    EUS = EnemyUnitState.EUS_IDLE;
                    _navMeshAgent.ResetPath();
                }
            }
            else
            {
                //transform.position += difference.normalized * Time.deltaTime * f_speed;
                LookDirection();
                _navMeshAgent.ResetPath();
                _navMeshAgent.SetDestination(go_LockOnUnit.transform.position);
            }
        }
        else
        {
            if (isDefending)
            {
                EUS = EnemyUnitState.EUS_DEFEND;
            }
            else
            {
                EUS = EnemyUnitState.EUS_IDLE;
                _navMeshAgent.ResetPath();
            }
        }
    }
コード例 #4
0
    void Attack()
    {
        if (go_LockOnUnit != null)
        {
            if (go_LockOnUnit.GetComponent <PlayerUnitInfo>().f_HealthPoint > 0)
            {
                Vector3 difference = go_LockOnUnit.transform.position - transform.position;

                if (difference.sqrMagnitude < f_atkRange * f_atkRange)
                {
                    _animator.SetTrigger("b_IsAttacking");
                    Vector3 look = go_LockOnUnit.transform.position;
                    look.y = transform.position.y;
                    transform.LookAt(look);
                    if ((f_fireCooldown += Time.deltaTime) >= 1 / f_fireRate)
                    {
                        f_fireCooldown = 0;
                        if (ET == EnemyType.ET_RANGED)
                        {
                            FireBullet(difference.normalized);
                        }
                        else
                        {
                            AttackUnit(go_LockOnUnit);
                        }
                    }
                }
                else
                {
                    EUS = EnemyUnitState.EUS_CHASE;
                }
            }
            else
            {
                go_LockOnUnit = null;
                EUS           = EnemyUnitState.EUS_IDLE;
            }
        }
        else
        {
            EUS = EnemyUnitState.EUS_IDLE;
        }
    }
コード例 #5
0
    void Idle()
    {
        GameObject tempPlayer = DetectPlayerUnit();

        _animator.ResetTrigger("b_IsAttacking");
        _animator.ResetTrigger("b_IsMoving");
        if (tempPlayer != null)
        {
            if ((tempPlayer.transform.position - transform.position).sqrMagnitude <= f_range * f_range)
            {
                go_LockOnUnit = tempPlayer;
                EUS           = EnemyUnitState.EUS_CHASE;
            }
            else if (isMoving)
            {
                EUS = EnemyUnitState.EUS_MOVE;
            }
        }
        else if (isMoving)
        {
            EUS = EnemyUnitState.EUS_MOVE;
        }
    }