L
L
LittleBob2021-12-13 20:42:29
Unity
LittleBob, 2021-12-13 20:42:29

How to get GameObject using OnTriggerEnter2D?

There is a player. When it collides with some kind of collider (trigger), I need to get a reference to the object on which this collider hangs. Let's say the hero collided with a tree. I need to get the GameObject of the tree through this collision. How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2021-12-13
@LittleBob

Well, OnTriggerEnter has a required parameter. From him and take the gameObject,

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question