Prevent Double Jump Challenge

I did a check for both the button being pressed and the collider touching the layer. It didn’t make sense to process the check for the ground layer if they weren’t pressing a button. I soon found that the inverse didn’t make a lot of sense either, so I put them both on one line.

private void Jump()
{
    if(CrossPlatformInputManager.GetButtonDown("Jump") && myCollider2D.IsTouchingLayers(LayerMask.GetMask("Ground")))
    {
        Vector2 jumpVelocityToAdd = new Vector2(0f, jumpForce);
        myRigidBody.velocity += jumpVelocityToAdd;
    }
}
1 Like

Privacy & Terms