- Home /
Question by
GhostlyDonut5 · Oct 24, 2016 at 09:22 AM ·
arraysparentlistsparentingparent-child
Making a list of obect's parents their parents from one script.
So here I'm getting a list of Objects, then getting the objects inside of each of their Lists.
targs = GetComponent<Proxemics>().targets; //Array from Proxemics.cs
for (int i = 0; i < targs.Length; i++)
{
objs = targs[i].GetComponent<ContentModule>().Objs;//List of Objects from ContentModule.cs
for (int j = 0; j < objs.Count; j++)
{
spaceObjectPrefabs.Add(objs[j]);
}
}
ContentModule.cs is attached to each of the targets from Proxemics.cs' array
So now I have all of the objects inside of each list. Now, I'm instantiating them for each Object that exists in the spaceObjectPrefabs List.
GameObject Object = Instantiate(item, new Vector3(0, 0, 0), rotation) as GameObject;
Object.transform.parent = gameObject.transform;
My question is how do I make each of these Object's parents the object that they originally belong to via their list. Sorry I'm trying my best to explain this and even I'm confused, only in psudocode can I explain.
foreach obj in spaceObjectPrefabList
transform.parent = object_that_holds_obj's_original_list.transform
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612095320im_/https://answers.unity.com/themes/thub/images/avi.jpg)