2d collision detection not working

I’m not sure what I’m doing wrong here. Theres a prefab of a wall. it spawn randomly and falls down. The player has to dodge it. Heres the code:

function OnCollisionEnter(col : Collision) {
	print("collision");
}

(Attached to the player)

I’ve tried many combinations of each having box collider and rigid body components. Nothing seems to work. Which objects need which components or is there something wrong with the code? I’ve also tried doing OnTriggerCollision with no results either.

This is because you are using the 3D version of collision. For 2D you need to change, like so

function OnCollisionEnter2D (col : Collision2D)
{
    print("collision");
}