Esempio n. 1
0
    int getHorizontalInput()
    {
        int direction = 0;

#if UNITY_EDITOR
        direction = (int)Input.GetAxisRaw("Horizontal");
#endif

        if (direction == 0)
        {
            if (leftButton.IsBtnPressed())
            {
                direction = -1;
            }
            else if (rightButton.IsBtnPressed())
            {
                direction = 1;
            }
        }


        return(direction);
    }
Esempio n. 2
0
    void FixedUpdate()
    {
        if (!sr.isVisible)
        {
            OnBecameInvisible();
        }

        float   horzMove = getHorizontalInput();
        Vector2 vect     = rb.velocity;

        rb.velocity = new Vector2(horzMove * speed, vect.y);

        if (horzMove > 0 && !facingRight)
        {
            FlipSprite();
        }
        else if (horzMove < 0 && facingRight)
        {
            FlipSprite();
        }
        float vertMove = jumpButton.IsBtnPressed() ? 1 : Input.GetAxis("Jump");

        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);
        }

        if (IsOnGround() && !isJumping)
        {
            anim.SetBool("isJumping", false);
            if (vertMove > 0)
            {
                isJumping = true;
            }
        }
        else
        {
            anim.SetBool("isJumping", true);
        }

        if (jumpButtonPressTime > maxJumpTime)
        {
            vertMove = 0;
        }

        if (isJumping && jumpButtonPressTime < maxJumpTime)
        {
            rb.velocity = new Vector2(rb.velocity.x, jumpSpeed);
        }

        if (vertMove >= 1)
        {
            jumpButtonPressTime += Time.deltaTime;
        }
        else
        {
            isJumping           = false;
            jumpButtonPressTime = 0;
        }

        isJumpingPressed = false;
    }