- Home /
Question by
Skatola · Aug 21, 2014 at 11:07 PM ·
instantiaterandom
gameobject spawn in randomrange coordinates
hi all :) like in the title i have to spawn my gameobject in random range coordinates, but i dunno how i can do that. i wrote this script:
function spawn () {
spawnpos = Random.Range(1,4);
if (spawnpos == 1)
Instantiate(enemy1, Vector3(Random.Range(-10,10),-6,0));
if (spawnpos == 2)
Instantiate(enemy1, Vector3(-10,Random.Range(-6,6),0));
if (spawnpos == 3)
Instantiate(enemy1, Vector3(Random.Range(-10,10),6,0));
if (spawnpos == 4)
Instantiate(enemy1, Vector3(10,Random.Range(-6,6),0;));
}
but didn't work...what i'm doing wrong? :\ thank you all for your help!
Comment
i've edited the code, now this is it:
function spawn () {
spawnpos = Random.Range(1,4);
if (spawnpos == 1)
Instantiate(enemy1, Vector3(Random.Range(-10,10),-6,0), transform.rotation);
if (spawnpos == 2)
Instantiate(enemy1, Vector3(-10,Random.Range(-6,6),0), transform.rotation);
if (spawnpos == 3)
Instantiate(enemy1, Vector3(Random.Range(-10,10),6,0), transform.rotation);
if (spawnpos == 4)
Instantiate(enemy1, Vector3(10,Random.Range(-6,6),0), transform.rotation);
}
still errors: unexpected token, seems like a sintax error (for now)
solved, changed "transform.rotation" with "quaternion.identity" and worked fine, sry for the thread and thank you all :)
Answer by SterlingStudios · Aug 21, 2014 at 11:54 PM
You have a semi-colon after the 0 on line 11 that should not be there.