Other.tag vs.other.gameobject.tag

Hi there,

while following the course, I remember that Rick once used other.gameObject.tag which is working fine. Now in this lecture, snow boarder hitting the finish line he uses other.tag which in my case does not work.

Am I missing out sth. or did something in Unity change…

Thanks a lot!

you have to make sure you are using the correct callback.

OnCollisionEnter2D() gives you a Collision2D. A Collision2D does not have a tag. When you get a Collision2D you have to use collision.gameObject.tag.

OnTriggerEnter2D() gives you a Collider2D. A Collider2D does have a tag. With a Collider2D you can use other.tag.


Edit In this lecture we are using a trigger, so you want to use the OnTriggerEnter2D() callback, not the OnCollisionEnter2D()

1 Like

Wow! That was fast…

Turned out I mixed things up. Time to finish for today :slight_smile:

Thanks a lot!

No problem. Enjoy the rest of the course

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms