Parent Multiple Clones to a New Parent?

I need to parent a series of cloned gameobjects tagged as “monarch” to a single gameobject tagged as “control”.

The script/s that instantiates them are written in UnityScript and too complicated for my limited experience to modify (and I tried) so I am now trying to parent them all AFTER they spawn, using a simple script written in C#.

The script below works fine to parent a single clone but, after searching online for answers and trying many different permutations to the code (inc. “FindGameObjectsWithTag” and GameObject) I still can’t get my head around how to parent them all.

Can anyone help me out?

Thanx in advance…


using UnityEngine;
using System.Collections;

public class ParentGameObjects : MonoBehaviour
	
{ 
	private GameObject monarch;
	private GameObject control;
	
	void Start ()
	{
		monarch = GameObject.FindGameObjectWithTag ("monarch");
		control = GameObject.FindGameObjectWithTag ("control");
		
		monarch.transform.parent = control.transform;
	}
}

Methods like GameObject.Find affects performance significantly if you use them constantly. But it’s totally okay if you only need to use it on start.

Now, you’re going to need to get all the game objects that’s tagged “monarch” and put them into an array then iterate through that array to parent the elements to the “control” game object one by one.

private GameObject[] monarchObjects;
private GameObject control;

void Start()
{
    control = GameObject.FindGameObjectWithTag ("control");
    monarchObjects = GameObject.FindGameObjectsWithTag("monarch");

    for(int i = 0; i < monarchObjects.length; i++)
    {
        monarchObjects*.transform.parent = control.transform;*

}
}