# distance

> The distance the physics query traversed before it detected a Collider2D.

## Definition

* **Type:** Property
* **Namespace:** [UnityEngine](/engine/6000.0/script-reference/unityengine.md)
* **Assembly:** UnityEngine.Physics2DModule

```csharp
public float distance { get; set; }
```

### Remarks

When the [RaycastHit2D](/engine/6000.0/script-reference/unityengine/raycasthit2d.md) result is returned from a physics query, the `distance` refers to the distance from the physics query start position to the position the physics query shape intersected as indicated by [RaycastHit2D.centroid](/engine/6000.0/script-reference/unityengine/raycasthit2d/centroid.md). For simple linecast or raycast queries, [RaycastHit2D.point](/engine/6000.0/script-reference/unityengine/raycasthit2d/point.md) is used to calculate the distance.

Additional Resources: [RaycastHit2D.fraction](/engine/6000.0/script-reference/unityengine/raycasthit2d/fraction.md).

### Examples

```csharp
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    public Vector2 direction;

    void Update()
    {
        // Cast a ray in the specified direction.
        RaycastHit2D hit = Physics2D.Raycast(transform.position, direction);

        // If we hit something that was less than 6 world units away then write a message.
        if (hit && hit.distance < 6f)
            Debug.Log("Hit something within range!");
    }
}
```
