Puzzle logic stuck

Hi All, I’m making a puzzle game in unity 2d with a grid of empty game objects with attached trigger box collider 2d and six cards (sprites) with trigger box colliders 2d.
I have a scene with the six cells of the grid at 0.0f of Z position and six cards with sorting order “2” and this script attached:

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

public class Card : MonoBehaviour
{
    public int num;
    private Vector3 offset;

    private void OnMouseDown()
    {
        offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10.0f));

        this.GetComponent<SpriteRenderer>().sortingOrder = 3;
    }

    private void OnMouseUp()
    {
        this.GetComponent<SpriteRenderer>().sortingOrder = 2;
    }

    void OnMouseDrag()
    {
        Vector3 newPosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10.0f);
        transform.position = Camera.main.ScreenToWorldPoint(newPosition) + offset;
    }

    private void OnTriggerEnter2D(Collider2D col)
    {
        Debug.Log(col.gameObject.name);
    }
}

This prints all, even the underlying cards(but I need that the cards trigger the cells) , and the cards, after a first drag, stops to move on mouse drag…
I’ve noticed taht if I omit OnMouseUp and OnTriggerEnter2D, it makes the drag always.
Why?
How can I fix the problem?

So on each grid, it needs to check if the card placed on it is the right one?

If yes, change your ontriggerenter with what I have here (note I’m not using an IDE, so if there are spelling mistakes or something like that I can’t see them, ALSO BE SURE TO ADD THIS TO VARIABLES: int theMatchingID)

	OnTriggerEnter2D(Collider2D col)
	{
		if(col.gameObject == grid.gameObject //or something like that
		{
                    theMatchingID = col.GetComponent<WhateverClassStoresTheGridID>()gridID // or something like that
			CheckCardInt(num);
		}
	}

And then add this function:

CheckCardInt(int ID)
	{
		if(ID == theMatchingID // or something like that
		   {
			   ThenWeHaveAMatchingID(); //or something like that
		   }
	}

Try that, I think it should work.

Ok, I came up with this code:

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

public class Card : MonoBehaviour
{
    public int num;
    public int matchingID;
    public bool moved;

    private GameObject logic;
    private Vector3 offset;

    private void Start()
    {
        logic = GameObject.Find("PuzzleLogic");
        moved = false;
    }

    void OnMouseDown()
    {
        this.GetComponent<SpriteRenderer>().sortingOrder = 3;
        offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10.0f));
    }

    void OnMouseUp()
    {
        this.GetComponent<SpriteRenderer>().sortingOrder = 2;
    }

    void OnMouseDrag()
    {
        moved = true;

        Vector3 newPosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10.0f);
        transform.position = Camera.main.ScreenToWorldPoint(newPosition) + offset;
    }

    void OnTriggerEnter2D(Collider2D col)
    {
        if (col.gameObject.tag == "Grid" && moved == true)
        {
            matchingID = col.GetComponent<Cells>().gridID;
            CheckCard(num, col.gameObject);
        }
    }

    private void OnTriggerStay2D(Collider2D col)
    {
        if (col.gameObject.tag == "Grid" && moved == true)
        {
            matchingID = col.GetComponent<Cells>().gridID;
            CheckCard(num, col.gameObject);
        }
    }

    void CheckCard(int ID, GameObject col)
    {
        if (ID == matchingID)
        {
            Debug.Log(ID);
            //logic.GetComponent<PuzzleLogic6>().count++;
            transform.position = col.gameObject.transform.position;
            this.GetComponent<SpriteRenderer>().sortingOrder = 2;
            this.GetComponent<Card>().enabled = false;
        }
    }
}

This seem to work: the cards lock in the position of the cells but I have a problem:
It prints the ID even if the dragged card is not over the matching ID…
Why?