Assign a prefab as childs to several gameobjects

Hi everyone,

In my scene I have numerous cubes, I added a tag to all these cubes, than I would like to assign this prefab as child to each cubes.
How can I manage this ?

To find gameobject with tag I use:

“GameObject.FindGameObjectsWithTag ;” and then "foreach (GameObject X in Y) "

I’m kind of beginner in scripting.

Thank you for your time and your help. Regards,

You can do something like that:

public void InstantiateInAllObjectsWithTag(GameObject original, string tag)
    var allTargets = GameObject.FindGameObjectsWithTag(tag);

    foreach (var target in allTargets )
        GameObject instance = Instantiate(original) as GameObject;