Custom Trigger 2D
What it does
CustomTrigger 2D is an extended polygonal trigger that, unlike the standard Unity 2D trigger system, allows for interaction with non-rigidbody gameobjects with both 2D and 3D colliders. This is used for scenes where you don't want to add a unnecessary rigidbody to every object that needs to interact with a trigger, or for 2.5D games that have both 2D and 3D objects/colliders.
How to use
You can add a custom trigger to any object by using the Add Component menu (Add Component -> Physics2D -> Custom Trigger 2D).
Editing the Trigger
With the object selected hold "Shift" to enter edit mode, you will see green handles appear on each vertex of the trigger. Click and drag handles to move vertices.
Click left mouse while in edit mode on the lines of the trigger to add new vertices.
Hold "Control" to enter deletion mode. Click (left mouse) on a vertex with control held down to delete vertices.
- Interact with 2D - Whether the trigger will interact with Collider2D
- Interact with 3D - Whether the trigger will interact with Collider
- Polygon Vertices - The position of the vertices in local space.
The trigger methods that will be called on the on any script in the same game object are:
Called once for every object that enters the trigger:
void CustomOnTrigger2DEnter(GameObject obj)
Called once for every object that exits the trigger:
void CustomOnTrigger2DExit(GameObject obj)
Called once a frame for every object that is inside the trigger:
void CustomOnTrigger2DStay(GameObject obj)
- Non-Rigidbody2D interaction supported
- Supports both 2D and 3D Colliders
- In scene view trigger editing
- Drag and Drop usage