# collider

> The Collider2D detected by the physics query.

## Definition

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

```csharp
public Collider2D collider { get; }
```

### Remarks

When the [RaycastHit2D](/engine/6000.0/script-reference/unityengine/raycasthit2d.md) result is returned from a physics query, the `collider` refers to the specific [Collider2D](/engine/6000.0/script-reference/unityengine/collider2d.md) that was detected.

**NOTE**: This field will be NULL if nothing was detected however when checking if the result is valid, you should use the less verbose method shown in the code example below.

Additional Resources: [RaycastHit2D.rigidbody](/engine/6000.0/script-reference/unityengine/raycasthit2d/rigidbody.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 something was hit, delete the specific Collider we hit.
        if (hit)
            Destroy(hit.collider);
    }
}
```
