I have seen this problem solved in the discussion but I didn’t understand what to do
It should be other.gameObject
(lowecase ‘g’). C# is case sensitive, so GameObject
is not the same as gameObject
Thank you it did work , but why can’t i use other.tag , it did work out well in the lecture
Collision2D
does not have a tag
property because it’s not a MonoBehaviour
. When you do OnCollisionEnter2D
you get a Collision2D
object that holds information about the collision. When you use OnTriggerEnter2D
(note trigger not collision) you get the Collider2D
that caused the trigger. Collider2D
is a MonoBehaviour
and has a tag
property.
So, when you use OnTriggerEnter2D
you can use other.tag
, but when you use OnCollisionEnter2D
you need to get the gameObject
the collided (and is stored as part of the collision info) and then get the tag
from that object
Thank you so much for your help I really appreciate it
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.