Help With OnCollision2D {Resolved}

Hello everybody I was working on a recent project when I came across this problem. When I run it and I make this GameObject, “Player”, collide with “Coin” the console only outputs “Working 1.” Any suggestions help! Thank you so much!

    void OnCollisionEnter2D(Collision2D other){
        Debug.Log ("Working 1");
        if(other.gameObject.tag == "Coin"){
            Debug.Log ("Working 2");
            Destroy(other.gameObject);
           
        }
    }

Is it tagged as Coin or is it named Coin?

It is named. Can you explain the difference?

The manual on tags does a much better job of explaining it than I could here in this post.

For now, you could just change your code to use the name instead of the tag:

if(other.gameObject.name == "Coin"){

But that might fall apart in the future if you have different coin prefabs (say blue and red) or instantiate them via code (then they’ll be called “Coin (Clone)”), so I’d still recommend you learn about tags and assign them a coin tag.

Thank you so much!