# RaycastAll

> Additional Resources: Physics.Raycast.

## Definition

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

## RaycastAll(Vector3, Vector3, float, int, QueryTriggerInteraction)

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

```csharp
public static RaycastHit[] RaycastAll(Vector3 origin, Vector3 direction, float maxDistance, int layerMask, QueryTriggerInteraction queryTriggerInteraction)
```

### Parameters

**** (\[Vector3]\(/engine/6000.5/script-reference/unityengine/vector3)): The starting point of the ray in world coordinates.**** (\[Vector3]\(/engine/6000.5/script-reference/unityengine/vector3)): The 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.5/script-reference/unityengine/querytriggerinteraction)): Specifies whether this query should hit Triggers.

### Returns

| Type                                                                        | Description |
| --------------------------------------------------------------------------- | ----------- |
| [RaycastHit\[\]](/engine/6000.5/script-reference/unityengine/raycasthit.md) |             |

### Remarks

See example above.

## RaycastAll(Ray, float, int, QueryTriggerInteraction)

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

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

### Parameters

**** (\[Ray]\(/engine/6000.5/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.5/script-reference/unityengine/querytriggerinteraction)): Specifies whether this query should hit Triggers.

### Returns

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

### Remarks

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

```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;
            }
        }
    }
}
```

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