2D Collision Not Working

I am making a game and part of it is navigating through obstacles. The player is a cube and the obstacles are cubes and i have a 2D Box Collider and 2D Rigidbody(with gravity turned off) on each. This is the script i have attached to the obstacle prefab.

using UnityEngine;

using System.Collections;

public class PlayerCollision : MonoBehaviour {

	void OnColliderEnter2D (Collider2D coll) {

		if(coll.gameObject.tag == "Player") {

			Destroy(gameObject);

		}

	}
}

When I run the game and run the player into the obstacle nothing happens. Any help is appreciated, thanks in advance!

You should be using OnCollisionEnter2D( Collision2D other ) {}

Hi,
please use the latest updated code.

using UnityEngine;

using System.Collections;

public class PlayerCollision : MonoBehaviour

{

void OnCollisionEnter2D(Collision2D coll) 
{

	if (coll.collider.tag == "Player") 
	{

		Destroy(gameObject);
            }

}

}

public class PlayerCollision : MonoBehaviour {

     void OnCollisionEnter2D (Collider2D coll) {
 
         if(coll.gameObject.tag == "Player") {
 
             Destroy(gameObject);
 
         }
 
     }
 }

Try this. It’s work defiantly…

i apologize ,it’s work fine.

void OnCollisionEnter2D(Collision2D coll)
{
if (coll.gameObject.tag == “Player”)
{
Destroy(gameObject);
}
}