I have a static Player class that I have a Jump method in it. It takes a Rigidbody2D parameter so I have to call it by typing
Player.Jump(GetComponent<Rigidbody2D>);
but I want to get the Rigidbody2D component in the Jump method and call it by typing
Player.Jump();
Is there any way to do this? Can I get the Rigidbody2D component from the Jump method?
My Jump code:
    /// <summary>
    /// Makes the given Rigidbody2D jump.
    /// </summary>
    public static void Jump(Rigidbody2D rb)
    {
        rb.velocity = new Vector2(rb.velocity.x, 0);
        rb.AddForce(new Vector2(0, JumpHeight));
    }
Class that I'm using the Jump method
if (Player.CanMove)
    {
        Player.Move(rb);
        if (Input.GetKeyDown(KeyCode.Space) && canJump)
        {
            if (tempMaxJumps > 0)
            {
                Player.Jump(rb);
                tempMaxJumps--;
            }
            else
            {
                canJump = false;
            }
        }
    }