- Home /
 
               Question by 
               FlannelFantasyXIV · Jan 27, 2014 at 08:29 PM · 
                instantiatecloneparenting  
              
 
              How to Parent a Cloned Object to Another Cloned Object
So I'm working on a procedurally generated endless runner kind of thing, it's my first real Unity project. I have a plane that slides forward, and then instantiates another plane, then destroys the first one. I'm trying to clone rock fragments that will be parented to the clones of the original plane, however I'm having some difficulty. Really, all I want to know is how to parent a clone to another clone. So I'm just gonna copy the whole chunk of code for the respawning plane here. Thanks for taking the time to read this!
 #pragma strict
 
 var respawnquery;
 var respawnlocation = 4;
 
 function Start () {
         respawnquery = false;
         
 }
 
 function Update () {
 
     transform.position.z -= 4 * Time.deltaTime;
 
     if(!respawnquery)
         respawn();
     
     if(respawnquery)
         destroy();
 }
 
 function respawn(){
 
     //respawning the ground plane
     
      respawnquery = true;
     yield WaitForSeconds(7.45);
     respawnlocation = 4;
     Instantiate(gameObject, Vector3.zero, transform.rotation);
     
     
     // for spawning rocks as children of background plane
     
     var rockSpawnLocation = Vector3(Random.value, Random.value, 0);
    
     var rocksClone : GameObject; 
     rocksClone = GameObject.Find("rockPrefab");
     Instantiate(rocksClone, rockSpawnLocation, transform.rotation);
     rocksClone.transform.parent = GameObject.Find("Background").transform;
     
     
     
 }
 
 function destroy(){
     yield WaitForSeconds(20);
     Destroy(gameObject);
 }
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                