Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        float speedX = Input.GetAxis("Horizontal");

        if ((speedX > 0 && !facingRight) || (speedX < 0 && facingRight))
        {
            Flip();
        }

        if (speedX == 0)
        {
            playerAnimation.PlayerIdle(true);
        }

        if (speedX != 0 && rbody.velocity.y == 0)
        {
            playerAnimation.PlayerRun(true);
        }

        if (Input.GetAxis("Fire1") != 0)
        {
            playerAnimation.AttackAnim(true);
        }

        if (IsPlayerOnRightWall() || IsPlayerOnLeftWall())
        {
            rbody.gravityScale = 0;
            rbody.velocity     = new Vector2(speedX * playerSpeed, 0);
        }
        else
        {
            rbody.velocity     = new Vector2(speedX * playerSpeed, rbody.velocity.y);
            rbody.gravityScale = 1;
        }



        if (Input.GetKeyDown(KeyCode.Space))
        {
            //rbody.velocity = new Vector2(speedX * playerSpeed, rbody.velocity.y);
            //Debug.Log("Space was pressed");

            if (IsPlayerOnGround())
            {
                rbody.velocity = Vector2.up * jumpHeight;
                playerAnimation.PlayerJump(true);
            }
            if (IsPlayerOnRightWall())
            {
                //Debug.Log("Space was pressed on right wall");
                //rbody.gravityScale = 1;
                //rbody.position.Set(rbody.position.x - 2f, rbody.position.y);
                rbody.position = new Vector2(rbody.position.x - 0.2f, rbody.position.y);
                //rbody.AddForce(new Vector2(jumpPushForce, jumpVertForce));
                rbody.velocity = new Vector2(jumpPushForce, jumpVertForce);
            }
        }

        //Debug.Log(rbody.velocity);
    }