Description
The OnTriggerEnter
property of the Collider
class is an event that is triggered when another collider enters the trigger area of this collider. This property is of type System.Action<Collider>
, allowing you to assign a delegate that will be called with the entering collider as a parameter.
Usage
To use the OnTriggerEnter
property, you need to ensure that the collider is set as a trigger by setting the IsTrigger
property to true
. Then, you can assign a method to OnTriggerEnter
to handle the event when another collider enters the trigger area.
Example
// Example of using OnTriggerEnter
Collider myCollider = new Collider();
myCollider.IsTrigger = true;
myCollider.OnTriggerEnter = (Collider other) =>
{
// Handle the event when another collider enters this trigger
Log.Info($"Collider {other} has entered the trigger area.");
};