# OnTriggerEnter2D(Collider2D)

> Sent when another object enters a trigger collider attached to this object (2D physics only).

## Definition

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

## OnTriggerEnter2D()

```csharp
public void OnTriggerEnter2D(Collider2D collider2D)
```

### Parameters

**** (\[Collider2D]\(/engine/6000.3/script-reference/unityengine/collider2d)):&#x20;

### Remarks

Further information about the other collider is reported in the Collider2D parameter passed during the call. This message is sent to the trigger Collider2D and the Rigidbody2D (if any) that the trigger Collider2D belongs to, and to the Rigidbody2D (or the Collider2D if there is no Rigidbody2D) that touches the trigger. **Note:** Trigger events are only sent if one of the Colliders also has a Rigidbody2D attached. Trigger events are sent to disabled MonoBehaviours, to allow enabling Behaviours in response to collisions. Additional Resources: [Collider2D](/engine/6000.3/script-reference/unityengine/collider2d.md) class, OnTriggerExit2D, OnTriggerStay2D. The following two script examples create an OnTriggerEnter2D demo. Example1 generates a Unity logo sprite, `GameObject1`. This sprite is collided with by the Example2 sprite, `GameObject2`. The Example1 script creates the [Rigidbody2D](/engine/6000.3/script-reference/unityengine/rigidbody2d.md). The kinematic mode is used on this script. Example2 supports the OnCollisionEnter2D method. This is called when GameObject2 collides with `GameObject1`. The script code for `GameObject2` controls the time it takes to collide with `GameObject1`. `GameObject2` is animated left-to-right repeatedly. When on the left side of the screen `GameObject2` moves right towards `GameObject1`. When these have collided `GameObject2` returns back to the left. The left side of the screen is the starting point for `GameObject2`. The right side of the screen is the constant position of `GameObject1`. The Example2 script code makes `GameObject2` collide with `GameObject1`. `GameObject2` stays collided for a short length of time.

### Examples

```csharp

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Example1 : MonoBehaviour
{
    private BoxCollider2D bc;
    private Rigidbody2D rb;

    void Awake()
    {
        SpriteRenderer sprRend = gameObject.AddComponent<SpriteRenderer>() as SpriteRenderer;
        sprRend.color = new Color(0.9f, 0.9f, 0.9f, 1.0f);

        bc = gameObject.AddComponent<BoxCollider2D>() as BoxCollider2D;
        bc.size = new Vector2(1.3f, 1.3f);
        bc.isTrigger = true;

        rb = gameObject.AddComponent<Rigidbody2D>() as Rigidbody2D;
        rb.bodyType = RigidbodyType2D.Kinematic;
    }

    void Start()
    {
        gameObject.GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("logo");
        gameObject.transform.Translate(4.0f, 0.0f, 0.0f);
        gameObject.transform.localScale = new Vector2(2.0f, 2.0f);
    }
}
```
