Create a Prefab instance

From ETC Public Wiki
Jump to: navigation, search

Create an instance of a Prefab

 var obj : GameObject;  // assign the obj in the Inspector
 
 function Create() {
   var go = Instantiate(obj, transform.position, transform.rotation);
   yield;  // give the obj time to create and run its start
   go.SendMessage("Setup");  // run any internal functions 
 }


Create with a base rotation

 Instantiate(obj, transform.position, Quaternion.identity);


Create with a random rotation

 Instantiate(obj, transform.position, Random.rotation);


set the parent

for the child object

 transform.parent = parentGO.transform;