# RaycastAll(Ray, float, int, QueryTriggerInteraction)

> Casts a ray through the Scene and returns all hits. Note that order of the results is undefined.

## Definition

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

```csharp
public static RaycastHit[] RaycastAll(Ray ray, float maxDistance, int layerMask, QueryTriggerInteraction queryTriggerInteraction)
```

### Parameters

**** (\[Ray]\(/engine/6000.7/script-reference/unityengine/ray)): The starting point and direction of the ray.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The max distance the rayhit is allowed to be from the start of the ray.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): A Layer mask that is used to selectively filter which colliders are considered when casting a ray.**** (\[QueryTriggerInteraction]\(/engine/6000.7/script-reference/unityengine/querytriggerinteraction)): Specifies whether this query should hit Triggers.

### Returns

| Type                                                                        | Description                                                                      |
| --------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
| [RaycastHit\[\]](/engine/6000.7/script-reference/unityengine/raycasthit.md) | An array of RaycastHit objects. Note that the order of the results is undefined. |

### Remarks

**Notes:** Raycasts will not detect colliders for which the raycast origin is inside the collider.

Additional Resources: [Physics.Raycast](/engine/6000.7/script-reference/unityengine/physics/raycast.md)

### Examples

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    void Update()
    {
        RaycastHit[] hits;
        hits = Physics.RaycastAll(transform.position, transform.forward, 100.0F);

        for (int i = 0; i < hits.Length; i++)
        {
            RaycastHit hit = hits[i];
            Renderer rend = hit.transform.GetComponent<Renderer>();

            if (rend)
            {
                // Change the material of all hit colliders
                // to use a transparent shader.
                rend.material.shader = Shader.Find("Transparent/Diffuse");
                Color tempColor = rend.material.color;
                tempColor.a = 0.3F;
                rend.material.color = tempColor;
            }
        }
    }
}
```
