Description
The IsTrigger
property of the Collider
class determines whether the collider behaves as a trigger. When set to true
, the collider will not physically interact with other colliders but will still generate trigger events. This is useful for creating areas that detect when objects enter or exit without affecting their movement.
Usage
To use the IsTrigger
property, simply set it to true
or false
depending on whether you want the collider to act as a trigger. When IsTrigger
is true
, you can handle trigger events using the OnTriggerEnter
and OnTriggerExit
properties, which are actions that can be assigned to handle the respective events.
Example
// Example of setting a collider as a trigger
Collider myCollider = new Collider();
myCollider.IsTrigger = true;
// Assigning actions to trigger events
myCollider.OnTriggerEnter = (collider) => {
// Code to execute when another collider enters this trigger
Log.Info($"Collider {collider} entered the trigger.");
};
myCollider.OnTriggerExit = (collider) => {
// Code to execute when another collider exits this trigger
Log.Info($"Collider {collider} exited the trigger.");
};