Ejemplo n.º 1
0
    void Move()
    {
        if (!animator.GetCurrentAnimatorStateInfo(0).IsName("Idle") &&
            !animator.GetCurrentAnimatorStateInfo(0).IsName("Move") &&
            !animator.GetCurrentAnimatorStateInfo(0).IsName("Jump") &&
            !animator.GetCurrentAnimatorStateInfo(0).IsName("DoubleJump") &&
            !animator.GetCurrentAnimatorStateInfo(0).IsName("Fall"))
        {
            return;
        }

        if (state == "DJUMP" && dJumpCount == 0)
        {
            rb.velocity = new Vector2(0, 2);
            this.rb.AddForce(new Vector3(0, 1, 0) * this.jumpForce * 0.5f);
            isDoubleJump = false;
            dJumpCount   = 1;
        }
        // 接地している時にSpaceキー押下でジャンプ
        if (animator.GetBool("isGround"))
        {
            aDriftCount = 0;
            dJumpCount  = 0;
            if (Input.GetKeyDown(KeyCode.Space) || UB_move.GetIsPressedDown())
            {
                this.rb.AddForce(new Vector3(0, 1, 0) * this.jumpForce);
                animator.SetBool("isGround", false);
            }
        }

        // 左右の移動。一定の速度に達するまではAddforceで力を加え、それ以降はtransform.positionを直接書き換えて同一速度で移動する
        float speedX = Mathf.Abs(this.rb.velocity.x);

        if (speedX < this.runThreshold)
        {
            this.rb.AddForce(transform.right * key * this.runForce * stateEffect * MasicEffect); //未入力の場合は key の値が0になるため移動しない
        }
        else
        {
            this.transform.position += new Vector3(runSpeed * Time.deltaTime * key * stateEffect * MasicEffect, 0, 0);
        }
    }
Ejemplo n.º 2
0
    public override void GetInputKey()
    {
        key          = 0;
        isDoubleJump = false;
        if (Input.GetKey(KeyCode.RightArrow) || UB_right.GetIsPressed()) //右
        {
            key = 1;
        }
        if (Input.GetKey(KeyCode.LeftArrow) || UB_left.GetIsPressed()) //左
        {
            key = -1;
        }
        if ((Input.GetKeyDown(KeyCode.Space) || UB_move.GetIsPressedDown()) && (!animator.GetBool("isGround")) && (state != "DJUMP"))//ジャンプボタン
        {
            isDoubleJump = true;
        }
        if (key != 0)
        {
            drec = key;
        }



        isDublePress = false;

        if ((Input.GetKeyDown(pressedKey) || UB_clone.GetIsPressedDown()) && pressedTime < 0.5f && isPress)
        {
            isDublePress = true;
            isPress      = false;
            pressedTime  = 0;
        }
        else if (Input.GetKeyDown(KeyCode.DownArrow) || UB_down.GetIsPressedDown() ||
                 Input.GetKeyDown(KeyCode.RightArrow) || UB_right.GetIsPressedDown() ||
                 Input.GetKeyDown(KeyCode.LeftArrow) || UB_left.GetIsPressedDown())
        {
            if (UB_up.GetIsPressed())
            {
                UB_clone = UB_up;
                isPress  = true;
            }
            else if (UB_down.GetIsPressed())
            {
                UB_clone = UB_down;
                isPress  = true;
            }
            else if (UB_left.GetIsPressed())
            {
                UB_clone = UB_left;
                isPress  = true;
            }
            else if (UB_right.GetIsPressed())
            {
                UB_clone = UB_right;
                isPress  = true;
            }
            else
            {
                foreach (KeyCode code in Enum.GetValues(typeof(KeyCode)))
                {
                    if (Input.GetKeyDown(code))
                    {
                        pressedKey = code;
                        isPress    = true;
                    }
                }
            }

            pressedTime = 0;
        }


        if (isPress)
        {
            pressedTime += Time.deltaTime;
        }
    }