Here there is a method OnTriggerEnter (Collider), it takes as a parameter the collider of that object, for example, the trigger of which it entered (well, that is, just the collider it entered).
And how to get the object itself, which entered the collider from the object itself with a trigger.
I hope I clearly wrote.

I understand that the trigger is the same collider, I just did not want to repeat.
Briefly: you do not need a trigger to get from an object, and the object that entered the trigger must be obtained from the trigger itself.

  • You will laugh, but collider.gameObject - eastwing
  • @eastwing and if there are several? - CGLike
  • Who are several? - eastwing
  • Objects included in the trigger - CGLike
  • So OnTriggerEnter is called several times - eastwing

2 answers 2

A trigger entry is an event that calls the OnTriggerEnter method. In each call, one collider is processed that is included in the trigger. To refer to his gameobject, you need to do this:

 GameObject obj = collider.gameObject; 

If you have several objects in the trigger at the same time, you can add them to any list and process them in a loop.

  • I do not call OnTriggerEnter. I have a trigger, on it there is a script, for example, and from this script I need to find out if anything is included in this trigger. - CGLike
  • one
    @CGLike documentation must be read, dear. They explain it to you in Russian language ...... in order to process this very input, you need to define the OnTriggerEnter method in the script which records this input itself ..... It receives an object collider which has a gameObject field in which is the object that entered the trigger - Aleksey Shimansky
  • @CGLike In general, to avoid misunderstandings, it is better to show some kind of your own code. For example, you could show event handling code. Because from your question it follows that the method you already have is defined - eastwing
  • Yes, I need the opposite, I know how OnTriggerEnter works, I don’t need to find a collision with an object for an object, I need to know WHAT HAPPENED TO A TRIGGER, FROM THE MOST TRIGGER, an object without triggers flies into a trigger and I need to find this object from the trigger, why? trigger trigger OnTriggerEnter if it is a trigger itself, and the object that flies into it does not have a collider - CGLike
  • @CGLike And I apologize to you, what are they writing about? Would you check how it works before writing caps on strangers - eastwing

In general, I found a solution, it turned out like this:

 foreach (Collider item in Physics.OverlapSphere (transform.position, Radius)) { if (item.attachedRigidbody && !item.isTrigger) { //...