How to destroy gameobjects with same tag using RaycastHit2D?

So, i have a problem with destroying a gameObject. I need to destroy a gameObjects with same tag that colliding with eachother but only when i press left mouse button and only ones that colliding with object that i clicked on. It sounds very complliceted…

void Update()
    {
        PlayerInput();
    }

    void PlayerInput()
    {
        if (Input.GetMouseButtonDown(0))
        {           
            CastRay();
        }
    }

    void CastRay()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, Mathf.Infinity);
        if (hit)
        {
               Destroy(hit.collider.gameObject);
        }
    }
}

Code destroying only one gameObject when i click on it.

mm if I understand you correctly it will help you

try this For 3D Project:

 void CastRay()
    {
        Ray ray = Camera.main.ScreenPointToRay( Input.mousePosition );
        RaycastHit hit;
        bool checkforray = Physics.Raycast( ray , out hit , Mathf.Infinity );

        if (checkforray)

        {
            Collider[] hitColliders = Physics.OverlapSphere( ray.origin , 5f );

            foreach (var nearcollider in hitColliders)
            {

                if (nearcollider.gameObject.tag==hit.collider.gameObject.tag)

                {
                    Destroy(nearcollider.gameObject);
                }

            }


        }
    }

try this for 2D Project:

   void CastRay()
    {
        RaycastHit2D ray = Physics2D.Raycast( Camera.main.ScreenToWorldPoint( Input.mousePosition ) , Vector2.zero );
        if (ray)
        {
            Collider2D[] hitColliders = Physics2D.OverlapBoxAll( ray.point , new Vector2(100 , 100 ),0f );
            foreach (var nearcollider in hitColliders)
            {
                
                if (nearcollider.gameObject.tag==ray.collider.gameObject.tag)

                {
                    Destroy( nearcollider.gameObject );
                }

            }
        }
    }

you can change the radius whatever you want
and