- Home /
Question by
jpcerrone · Nov 16, 2012 at 05:24 PM ·
javascriptfunctionstarttrees
Doing something mutiple times in function() Start
Hi everyone, i have this code function Update () {
//arboles
if (treeinstances < maxtrees)
{
var position: Vector3 = Vector3(Random.Range(transform.position.x - 225, (transform.position.x+225)),0.0,Random.Range(transform.position.z-225, (transform.position.z+225)));
Instantiate(tree, position, Quaternion.identity);
treeinstances += 1 ;
}
This creates trees untill they equal the max amount of trees, I want to do this all in the start function, how would you do it ?
Comment
Answer by mstevenson · Nov 16, 2012 at 06:43 PM
Change "if" to "while", and change < to ==
This will force the code inside the brackets to continue to run until treeinstances is equal to maxtrees.
Thank, you I did what you told but ins$$anonymous$$d of changing < to == I changed it to !=, and it worked