- Home /
Spawn object in random areas
Hello I need help in writing a javascript code to spawn my birds in my game.... i want to set up four empty gameobjects to be my spawn points and have my bird prefab spawn randomly in each spawnpoint infinitely but i have no idea on how to do that....can anyone help?
Answer by hero_kenshin · Feb 23, 2014 at 01:42 PM
I've done this before what i did was set up a variable to contain the transforms of all my spawnpoints like this
var Spawns : Transform[];
Connect that to your 4 spawn points (empty gameobjects)
next all you need to do is call instantiate using a Random.Range of your spawns like so
Instantiate( Bird, Spawns[Random.Range( 0, 3)].position, Spawns[0].rotation);
Alternatively you can acquire a random number before you Instantiate
var randomnum : int = Random.Range(0,3);
Instantiate( Bird, Spawns[randomnum].position, Spawns[randomnum].rotation);
Answer by XAngelBR · Feb 23, 2014 at 01:43 PM
I think this link can help you: http://answers.unity3d.com/questions/13657/mulitple-spawn-points-with-random-seed.html
Your answer
Follow this Question
Related Questions
Generate random number and set a GameObject active. 1 Answer
Random spawn timer 1 Answer
Calling random functions 4 Answers
How to spawn Prefab to a certain position. 2 Answers
Monster Spawner 3 Answers