Snap with collision trigger on child objectss

I want to add a snap option to two parent objects with their childs.
The collison is 2D with trigger.
Non-collided state is as belows:
101734-no-touch.jpg

After collison, i change the color of the part to green with:

void OnTriggerEnter2D(Collider2D other)
{

    if (other.gameObject.tag == "Board")
    {
        
        
        other.GetComponent<Renderer>().material.color = Color.white;
        GetComponent<Renderer>().material.color = Color.green;
       

     
    }
}

Then the state becomes as belows:

101735-touch.jpg

What I want to do is,if every part is green, on double click, keypres or whatever, I want to change all collided childs position to other collided objects position ( snap )

I can check the situation if everypart is green with :

   foreach (Renderer r in GetComponentsInChildren<Renderer>())
    {
        if (r.material.color != Color.green)
        {
            //do action

        }

The point I am stuck is to check the collision state of each component and equalize them to collided parts.

I would appreciate your help on the subject.

Thank you.

Good day @Ertunc !

Well, i’m not sure what you want to do. You want to change the worldPosition of the childs? or what you want is to change the parent of the childs and of course move it to correct the new parent position?

I supose you want the child/parent change. Let’s see then.

Lets make a GameObject variable called Sphere to refear an object called GOChild which is the child of the gameobject GOParent, using the transform.Find to look for childs

Shpere=GOParent.transform.Find("GoChild");

Now, lets change the parent of the Sphere, to become the child of an object called GOParentTwo

Sphere.transform.parent = GoParentTwo.transform

Now, the sphere is a child of the GOParentTwo, but you need to move it where you desire with the Sphere.transform.LocalPosition.

If what you want i to check if each sphere is colisioning, you must do it 1 by 1 with a script placed in each sphere with the OnTriggerEnter and checking the other collider.gameObject.transform.parent is another gameObject.

If this helps upvote !!

If is not what you asked for, just ask again, give more info, and use @tormentoarmagedoom !

Bye:D