Description
The Touching
property of the Collider
class provides a list of colliders that are currently interacting with this collider. The behavior of this property depends on whether the collider is set as a trigger or not:
- If the collider is a trigger, the
Touching
property will return all colliders that are currently touching this trigger.
- If the collider is not a trigger, the
Touching
property will return all triggers that this collider is currently touching.
Usage
To access the Touching
property, you need to have a reference to a Collider
instance. You can then iterate over the collection of colliders that are touching this collider:
Example
Collider myCollider = GetComponent<Collider>();
if (myCollider != null)
{
foreach (Collider touchingCollider in myCollider.Touching)
{
// Perform operations with touchingCollider
// For example, log the name of the touching collider
Log.Info($"Touching collider: {touchingCollider.Name}");
}
}