- Home /
Random Spawning
I asked a similar question to this earlier, but It was not answered quite the way I needed it. I need a default Cube to spawn to a random point when the level is loaded. I need it to be spawned differently each time the level is loaded. Any help would be greatly appreciated.
Answer by Dave-Carlile · Mar 04, 2013 at 03:41 PM
You can use Random.insideUnitSphere to create a random vector to use for the position.
Hard to say exactl the type of "random spawn" you're looking for, and exactly what you mean by "spawned differently each time". Is it completely random? Or do you want a list of spawn points that are selected from randomly? Can there be absolutely no repeated use of a spawn point? Or is it okay to potentially pick the same random spawn point twice?
A quick search finds a number of answers on the topic here:
http://answers.unity3d.com/questions/290477/how-to-set-up-random-spawnpoints.html http://answers.unity3d.com/questions/306624/how-can-i-create-a-script-to-create-and-then-rando.html
Sorry for the vague references. What I mean is, can you make an object spawn to a new location each time the level is loaded. Perhaps spawned to one of three positions or something.
Any better?
Both of the links in my answer describe how to select a random position. To do it when the level is loaded just put the selection of the spawn point inside the Awake function of one of your scripts.
Your answer
Follow this Question
Related Questions
How to set up random spawnpoints? 1 Answer
Random cube length on instantiate... 1 Answer
Spawing a SpawnPoint with Raycast 0 Answers
Room generator spawn 1 unique room 1 Answer
Procedural Generation... 2 Answers