OnCollisonEnter2D Not Firing after checking collider

I was trying to make a script to check if a collision. I am using:

public class Lose : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
    void OnCollisionEnter2D(Collision2D col) {
        if (col.gameObject.name=="ramp") { 
print("You lose");
         }
    }
}

I have googled it but nothing pops up.

When dealing with colliders there are a couple of things you have to be careful of. So check these things and hopefully you will find the problem.

  • You are using OnCollisionEnter2D, this means that both the objects involved must have a Rigidbody2D component attached to them.

  • They also both need Colliders of the 2D variety. Box Collider, Sphere Collider, etc will not work. You need to use BoxCollider2D, CircleCollider2D.

  • Make sure the name of your game object is “ramp” exactly. Case matters I believe.