# IntersectRay

> Does ray intersect this bounding box?

## Definition

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

## IntersectRay(Ray)

Does ray intersect this bounding box?

```csharp
public bool IntersectRay(Ray ray)
```

### Parameters

**** (\[Ray]\(/engine/6000.0/script-reference/unityengine/ray)):&#x20;

### Returns

| Type                                                          | Description |
| ------------------------------------------------------------- | ----------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) |             |

### Examples

```csharp
using UnityEngine;

public class Example : MonoBehaviour
{
    // Function to detect if a ray (representing a beam weapon, say)
    // makes contact with the collider's bounds.

    Collider myCollider;

    void Start()
    {
        // Store a reference to the collider once at startup.
        myCollider = GetComponent<Collider>();
    }

    bool DetectHit(Ray ray)
    {
        return myCollider.bounds.IntersectRay(ray);
    }
}
```

## IntersectRay(Ray, float)

Does ray intersect this bounding box?

```csharp
public bool IntersectRay(Ray ray, out float distance)
```

### Parameters

**** (\[Ray]\(/engine/6000.0/script-reference/unityengine/ray)): **** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)):&#x20;

### Returns

| Type                                                          | Description |
| ------------------------------------------------------------- | ----------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) |             |

### Remarks

When the function returns true, the distance to the ray's origin will be returned in the distance parameter.
