Why can't collision work for me?

I am making a game which requires the player to automatically move right and when it collides with a wall to turn around and walk straight until it collides with the left, then repeat infinitely. I have tried two methods of collision, 1. using tags, and 2. using layers. Either I am doing something wrong or unity just doesn’t like me.

I followed this tutorial almost to the letter.


Except I just took two square sprites, added a box collider, and rigidbody2d to it. Copy the links script exactly and in the end the two squares collide and thats it. The enemy object doesn’t get destroyed.

I figured out what I was doing wrong. I wrote void ‘OnCollision2D’ instead of void ‘OnCollisionEnter2D’