OnCollisionEnter not working I don't know why!

I am very new to Unity and C# and I was following a guide to learn som more about Unity, but I got stuck because the collision doesn’t work. I want the “Player” to get removed when it tocuhes the “Enemy” but when they touch nothing happens, I let Unity use the screwdriver tool to help fix it, but now the collision and the rest of the code doesn’t work. Please help I have been stuck for quite a while now.

public class PlayerMovement : MonoBehaviour
{
public float moveSpeed;
public Rigidbody2D rb;
private Vector2 moveDirection;

private void Start()
{
    //Destroy(gameObject, 3f);

}

void Update()
{
    float moveX = Input.GetAxisRaw("Horizontal");
    float moveY = Input.GetAxisRaw("Vertical");

    moveDirection = new Vector2(moveX, moveY).normalized;
}

void FixedUpdate()
{
    rb.velocity = new Vector2(moveDirection.x * moveSpeed, moveDirection.y * moveSpeed);
}

private void OnCollisionEnter(Collision collision)
{
    if (collision.gameObject.CompareTag("Enemy"))
    {
        Destroy(gameObject);
    }

}

Hi! It seems you are using the 3D on collision event, but are moving with 2D physics. Confusingly, these aren’t compatible.

Try this:

private void OnCollisionEnter2D(Collision2D collision)

instead of

private void OnCollisionEnter(Collision collision)