If you set up an edge collider on the objects you can use:
void Update()
{
//this detects the mouse position
Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
//this check to see if the mouse is over the collider documentation below
if (this.GetComponent<EdgeCollider2D>().ClosestPoint(mousePos) == mousePos)
{
print("mouse is hovering over object");
if(Input.GetKeyDown(KeyCode.Mouse0))
{
print("mouse clicked on object");
}
}
}
documentationFor more information, refer to the https://docs.unity3d.com/ScriptReference/Collider.ClosestPoint.htmldocumentation for Collider.ClosestPoint.