Why other.gameObject.tag ? not other.tag?

OnTriggerEnter2D can use other.tag before,
why OnCollisionEnter2D can only use other.gameObject.tag? I feel confused ,Please tell me the reason.

OnTriggerEnter2D gives you the collider that caused the trigger. The collider is on the game object and therefore has a tag.
OnCollisionEnter2D gives you a collision object. It is not on the game object, it is an object that holds information about the collision. One of those pieces of information is the game object you collided with. So, you need to get the tag of that game object.
I believe the reason for it being different is because you don’t need to know a lot of things when you have a trigger. Just that something activated it. But with a collision you may want a lot more information about the collision

1 Like

Thanks a lot. I get the difference.

1 Like

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

Privacy & Terms