W
W
WasTabon2022-02-13 17:48:00
Unity
WasTabon, 2022-02-13 17:48:00

How to find out who called OnTriggerEnter2D?

620919e951428093896443.png
I have a parent object and 3 attached to it (1 pair and a second object) with triggers and only 1 script that is attached to the parent, how to find out which of the 3 child objects called it with OnTriggerEnter2D?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2022-02-14
@tentrun

Make an event broker and subscribe objects to it

K
Keliorw, 2022-02-14
@Keliorw

You hang these lines of code on the object with which the objects you need will collide, after which you will get access to the object that collided with the object on which the script

public void OnTriggerEnter2D(Collider2D collision) 
{
   Debug.Log(collision.gameObject.name);
   if(collision.gameObject.name == "Имя того кого ищешь")
   {
        Действия
   }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question