- Home /
how to stack prefabs (with script)
Hello, i am currently trying to create an "ever growing tower" with prefabs. The idea is that when the player presses a button a prefab is instantiated and if it is not touching the roof then a clone of the prefab is instantiated but stacked on top of the previous one. I can get the prefab to enter the world but it then infinitely spawns new prefabs even though i have a boolean true/false in an if statement. They also all generate on the spawn point of the first prefab and not sequentially as desired.
So the question is how do i get these prefabs to stack on top of each other ( currently the prefab is a cylinder with a spawn point"addrope" on top), and only do it once not infinitely. the code is below.
Thanks in advance.
var ropeprefab : Transform;
var ihavespawned : boolean = false;
function Update () {
if(ihavespawned == false){
var rope=Instantiate(ropeprefab,GameObject.Find("addrope").transform.position,Quaternion.identity);
ihavespawned = true;
rope.transform.parent = ropeprefab.transform;
}
}
Comment