// Update is called once per frame void Update() { velocity.y += gravity * Time.deltaTime; controller.Move(velocity * Time.deltaTime); Controller2D.CollisionState state = controller.GetCollisionState(); bool grounded = (state & Controller2D.CollisionState.COLLIDE_BELOW) != 0; if ((state & (Controller2D.CollisionState.COLLIDE_BELOW | Controller2D.CollisionState.COLLIDE_ABOVE)) != 0) { velocity.y = 0.0f; } if ((state & (Controller2D.CollisionState.COLLIDE_LEFT | Controller2D.CollisionState.COLLIDE_RIGHT)) != 0 && velocity.y < -maxSlidingSpeed) { velocity.y = -maxSlidingSpeed; } }
// Update is called once per frame void Update() { Controller2D.CollisionState state = controller.GetCollisionState(); bool grounded = (state & Controller2D.CollisionState.COLLIDE_BELOW) != 0; bool wallGrounded = wallJump && (state & (Controller2D.CollisionState.COLLIDE_LEFT | Controller2D.CollisionState.COLLIDE_RIGHT)) != 0; if (jumping) { if (grounded || baseMovement.velocity.y <= 0) { jumping = false; } if (!jumping || !Input.GetButton("B_J")) { baseMovement.gravity = lowJumpGravity; } } if (grounded || wallGrounded) { jumpsCounter = jumpsNumber; } if (jumpsCounter > 0 && Input.GetButtonDown("B_J")) { Vector2 velocity = new Vector2(0, jumpVelocity); bool xReseting = false; if (wallGrounded && !grounded) { velocity.x = (state & Controller2D.CollisionState.COLLIDE_LEFT) != 0 ? wallJumpVelocity : -wallJumpVelocity; xReseting = true; } Jump(velocity, xReseting); } }