System.Action<GameObject> OnObjectTriggerEnter { get; set; }

book_4_sparkGenerated
code_blocksInput

Description

The OnObjectTriggerEnter property is an event handler that is invoked when a GameObject enters the trigger area of a Collider component. This property is particularly useful for detecting when objects interact with trigger zones in a scene, allowing developers to execute custom logic in response to these interactions.

Usage

To use the OnObjectTriggerEnter property, assign a method that matches the System.Action<Sandbox.GameObject> delegate signature. This method will be called whenever a GameObject enters the trigger area of the collider.

Ensure that the IsTrigger property of the Collider is set to true to enable trigger functionality.

Example

// Example of using OnObjectTriggerEnter
Collider myCollider = new Collider();

// Ensure the collider is set as a trigger
myCollider.IsTrigger = true;

// Assign a method to the OnObjectTriggerEnter event
myCollider.OnObjectTriggerEnter = (GameObject obj) =>
{
    // Custom logic when a GameObject enters the trigger
    Log.Info($"GameObject {obj.Name} has entered the trigger.");
};