Need help with weird OnMouseDown triggers,Need help with weird OnMouseDown Triggers

So i’m making a chess like game (2d), and to select a peice to move, you need to click it. I thought of using a OnMouseDown function, but only the first object i put on the scene responds to it, and it responds wherever i click.
Any help is apreciated!!,So im making this chess like game, and im making it so when you click a piece, it moves. My issue, is that wherever i click, it chooses the first one i put in the scene. Here is the code:

public class Movement : MonoBehaviour
{
void OnMouseDown()
{
manager.GetComponent().selected = self;
}
void Update()
{
// movement code
}
}

You could use a raycast from the mouse and check if it hits.

void OnMouseDown ()
{
    Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    RaycastHit2D hit = Physics2D.Raycast(mousePos, Vector3.zero);
    if (hit.collider != null && hit.collider.gameObject == gameObject)
     {
          manager.GetComponent<Manager>().selected = self;
     }
 }

Make sure to put a collider on your chess piece though, or else the raycast won’t hit.