Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

How to Parent a Cloned Object to Another Cloned Object

$
0
0
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); }

Viewing all articles
Browse latest Browse all 171066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>