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;
}
}
↧