# transform

> The Transform on the GameObject that the Collider2D is attached to.

## Definition

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

```csharp
public Transform transform { 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 however `transform` refers to the [Transform](/engine/6000.0/script-reference/unityengine/transform.md) on the [GameObject](/engine/6000.0/script-reference/unityengine/gameobject.md) that the [RaycastHit2D.collider](/engine/6000.0/script-reference/unityengine/raycasthit2d/collider.md) is attached to.

**NOTE**: `transform` is equivalent to using transform and is provided for convenience only. This field will be NULL if nothing was detected.

Additional Resources: [RaycastHit2D.collider](/engine/6000.0/script-reference/unityengine/raycasthit2d/collider.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 then move the transform to the world origin.
        if (hit)
            hit.transform.position = Vector3.zero;
    }
}
```
