How to limit the distance of a raycast?

So here’s my code.

Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f,0.5f,0.0f));

I’m just wondering how i can make the raycast only cast 2 units in front of me

Last example in the doc:

public class Example : MonoBehaviour {
    void Update() {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;
        if (Physics.Raycast(ray, out hit, 2))
            Debug.DrawLine(ray.origin, hit.point);
        
    }
}

Edit: To clarify: A ray does NOT have a length! It is only when you do the raycast you can limit the distance.

@VildNinja
How would you limit the distance of a raycast here?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ClickAndDestroy : MonoBehaviour
{
// Update is called once per frame
void Update()
{

    if (Input.GetMouseButtonDown(0))
    {

        RaycastHit hit;
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                MeshCollider bc = hit.collider as MeshCollider;
                if (bc != null)
                {
                    Destroy(bc.gameObject);
                }
            }
        }
    }
}