- Home /
Hierarchy question
Hi,
I'd like to create children of a GameObject through instantiate, but i have no clue whether it is possible or not.
Im using code below:
Company is filled with a prefab in the editor. The objCompany instances of this Prefab would preferably be children of the GameObject this script is attached to, but they are created as seperate gameobjects.
Any clues?
Thx B
var Company : Transform; var numCompanies=5;
var objCompany = new Array(Transform,Transform,Transform,Transform,Transform,Transform,Transform,Transform,Trans form,Transform);
function Awake() { for (var i=0;i<numCompanies;i++) { objCompany[i]=Instantiate(Company,Vector3(i,0,0),Quaternion.identity); }
}
Answer by Jason_DB · Feb 25, 2010 at 08:03 PM
It is possible to set parenting in a script using transform.parent, by adding in something like this
objCompany[i].parent = transform;