Collision script not working "Script error: OnCollisionEnter2D"

I know my code is messy, I just started learning. I am trying to make it so an object locks onto the object it collides with. I used this script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CollisionTest : MonoBehaviour
{
    public Vector2 Card1LockedPosition;
    public Vector2 Card2LockedPosition;
    public Vector2 Card3LockedPosition;
    public Vector2 Card4LockedPosition;
    public Vector2 Card5LockedPosition;

    void Start()
    {
        if (gameObject.name == "Card1O")
        {
            Card1LockedPosition = new Vector2(20.5f, -7.1f);
        }
        if (gameObject.name == "Card2O")
        {
            Card2LockedPosition = new Vector2(20.5f, -7.1f);
        }
        if (gameObject.name == "Card3O")
        {
            Card3LockedPosition = new Vector2(20.5f, -7.1f);
        }
        if (gameObject.name == "Card4O")
        {
            Card4LockedPosition = new Vector2(20.5f, -7.1f);
        }
        if (gameObject.name == "Card5O")
        {
            Card5LockedPosition = new Vector2(20.5f, -7.1f);
        }
    }


    void OnCollisionEnter2D(Collider col)
    {
        if (gameObject.name == "Card1O")
        {
            if (col.gameObject.tag == "Lockable")
            {
                Card1LockedPosition = col.gameObject.transform.position;
            }
        }
        if (gameObject.name == "Card1O")
        {
            if (col.gameObject.tag == "Lockable")
            {
                Card2LockedPosition = col.gameObject.transform.position;
            }
        }
        if (gameObject.name == "Card1O")
        {
            if (col.gameObject.tag == "Lockable")
            {
                Card3LockedPosition = col.gameObject.transform.position;
            }
        }
        if (gameObject.name == "Card1O")
        {
            if (col.gameObject.tag == "Lockable")
            {
                Card4LockedPosition = col.gameObject.transform.position;
            }
        }
        if (gameObject.name == "Card1O")
        {
            if (col.gameObject.tag == "Lockable")
            {
                Card5LockedPosition = col.gameObject.transform.position;
            }
        }
    }
}

But when my object hits the collider, It doesn’t stick to it. The only thing is I see is this message: “Script error: OnCollisionEnter2D”. Can someone help me? It’s probably something stupid and easy but thanks anyways. (The script is on the object that should be locked on another object on collision, all the objects have 2D box colliders and they are all sprites).

That should be:

void OnCollisionEnter2D(Collider2D col)

Sorry for the late reply, but it still isn’t working? It gives me the error

"Script error: OnCollisionEnter2D
This message parameter has to be of type: Collision2D"

I thought everything worked but clearly not sorry

oh i fixed it sorry for wasting your time :frowning:

oh… it isn’t working anymore

;-; what am i doing

Which aspect isn’t working?

oh well, I broke everything, I made in a new post in the Unity2d forum. Sorry for wasting your time :frowning: