Is it possible to get a reference to the object that entered the trigger in the OnTriggerEnter method?
|
1 answer
The answer is yes, you can get. Because OnTriggerEnter is just called when the Collider another object enters the trigger.
void OnTriggerEnter(Collider other) { GameObject enteredObject = other.gameObject; Debug.Log(enteredObject.name); } This message is sent to the trigger, and to its rigidbody (if any), and to the rigidbody (or collider, if there is no rigidbody ) that are in contact with the trigger.
Please note that trigger events are sent only if one of the colliders also has an attached rigidbody
What information can be obtained from the collider can be viewed at the docks in the Inherited members :
gameObject- just the object that entered the triggertag- object tagtransformhideFlagsname- the name of the object- other
|
который вошёл в триггер? The one that was outside the trigger, went and now literally enters the trigger? Or has the object once entered a trigger, is already there and you want to get it? - Alexey Shimansky