How can I tell if a player is close enough to an object to pick it up?

I’m using Raycasting to pickup items but right now it doesn’t matter how close my player is to the object to be able to pick it up. How can I check the distance between the player and the object?

void PickupWeapon()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        
        RaycastHit hit;
        Debug.DrawRay(ray.origin, ray.direction * 10, Color.red);

        if (Input.GetMouseButtonDown(0))
        {
            if (Physics.Raycast(ray, out hit) == true)
            {
                weaponToHold = hit.transform.gameObject;
                weaponToHold.transform.parent = hand.transform;
                weaponToHold.transform.position = hand.transform.position;
            }
        }
    }

The third parameter of Physics.Raycast is the max distance of the ray.

If you did:

            if (Physics.Raycast(ray, out hit, 3) == true)
            {
                weaponToHold = hit.transform.gameObject;
                weaponToHold.transform.parent = hand.transform;
                weaponToHold.transform.position = hand.transform.position;
            }

and it was 2 meters away it would return true.