Beispiel #1
0
    //モードの更新
    void ModeUpDate()
    {
        //攻撃範囲内
        if (NavPositionFlag(transform.position, playerCharacter.transform.position, enemy.attackRange))
        {
            //攻撃モード
            modeNow = ModeNow.attackMode;
        }
        //追跡範囲内
        else if (NavPositionFlag(transform.position, playerCharacter.transform.position, enemy.searchRange))
        {
            //追跡モード
            modeNow = ModeNow.chaseMode;
        }
        //それ以外
        else
        {
            //索敵モード
            modeNow = ModeNow.searchMode;
        }

        //敵のモードが変更されたとき
        if (modeLog != modeNow)
        {
            ModeChange();
        }

        modeLog = modeNow;  //ログの取得
    }
Beispiel #2
0
    void Update()
    {
        //重力の処理
        GravityControl();

        //Rayの接地判定が地面なら
        if (isGround && !attackFlag)
        {
            NavMeshHit navHit;
            //敵とプレイヤーの下にNavMeshがある場合
            if (!NavMesh.Raycast(transform.position + new Vector3(0f, 0.1f, 0f),
                                 transform.position - new Vector3(0f, 0.25f, 0f), out navHit, NavMesh.AllAreas) &&
                !NavMesh.Raycast(playerCharacter.transform.position + new Vector3(0f, 0.1f, 0f),
                                 playerCharacter.transform.position - new Vector3(0f, 0.25f, 0f), out navHit, NavMesh.AllAreas))
            {
                //どの動きをするかの更新
                ModeUpDate();
            }
            else if (modeNow == ModeNow.attackMode)
            {
                modeNow = ModeNow.searchMode;
            }

            switch (modeNow)
            {
            //索敵
            case ModeNow.searchMode:
                SearchMove();
                break;

            //追跡
            case ModeNow.chaseMode:
                ChasehMove();
                break;

            //攻撃
            case ModeNow.attackMode:
                attackMove();
                break;
            }
        }


        Animator animator = GetComponent <Animator>();

        animator.SetInteger("PState", playerState);

        //移動
        NavUpdate();

        Vector3 velocity = Vector3.zero;

        if (modeNow != ModeNow.attackMode && !windFlag)
        {
            //移動方向を向く
            targetAngleRotate(gameObject, navPosFlag ? navNextPosition : nextMovePosition, rotateSpeed);
            //正面に歩く
            velocity = transform.forward * speed;
        }

        rBody.velocity = new Vector3(velocity.x, gravity, velocity.z) + objectVelosity +
                         (windFlag ? new Vector3(windVelosityLog.x, 0f, windVelosityLog.z) : Vector3.zero);

        //敵の消滅処理
        if (transform.position.y < -10f)
        {
            Destroy(gameObject);
        }
    }