Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        if (isDead || player == null || playerController.isDead || !playerController.CanMove())
        {
            return;
        }

        //武器位置冻结
        if (weaponStandardAction.isActionFreeze)
        {
            weaponStandardAction.FreezeAction();
        }
        else
        {
            //不打断正在进行的动作
            weaponStandardAction.continueAction();
            if (weaponStandardAction.isActionOver)
            {
                float distance = (player.transform.position - transform.position).magnitude;
                if (weaponStandardAction.isPreAttackPosture() && distance < 4)
                {
                    //攻击
                    weaponStandardAction.Attack();
                    StartCoroutine(AttackActionCooldown());
                }
                else if (attackCooldownOver && distance < 5)
                {
                    //靠近玩家准备攻击
                    weaponStandardAction.PreAttack();
                }
                else if (changeCooldownOver && distance < 8)
                {
                    //切换姿态
                    ChangeAction();
                    StartCoroutine(ChangeActionCooldown());
                }

                transform.LookAt(player.transform);
                if (playerController.CanMove() && !playerController.isOutFirstCircle)
                {
                    //靠近玩家
                    if (distance > 2.5)
                    {
                        transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
                    }
                    else if (distance < 1.5)
                    {
                        transform.Translate(Vector3.back * moveSpeed / 2 * Time.deltaTime);
                    }
                }
            }
        }
    }
Exemple #2
0
    /**
     * 武器动作
     */
    private void WeaponAction()
    {
        bool leftMouse   = Input.GetButton("Fire1");
        bool leftMouseUp = Input.GetButtonUp("Fire1");

        // if (leftMouse)
        // {
        //     weaponStandardAction.PreAttack();
        // } else if (leftMouseUp)
        // {
        //     weaponStandardAction.Attack();
        // }
        if (leftMouseUp)
        {
            weaponStandardAction.PreAttack();
        }
        else
        {
            //上下
            float mousey = Input.GetAxis("Mouse Y");
            //左右
            float mousex = Input.GetAxis("Mouse X") * mouseSpeed;
            if (mousey > 0.5)
            {
                weaponStandardAction.upPosition();
            }
            else if (mousex > 0.5)
            {
                weaponStandardAction.rightPosition();
            }
            else if (mousex < -0.5)
            {
                weaponStandardAction.leftPosition();
            }
        }
    }