- Home /
How do you spawn 10 objects between multiple points?
Okay, so basically i have 15 sites on my map, and 10 objects that i'd like to spawn randomly between the 15 sites. I'm kind of new to scripting so I don't even know where to start.
The easiest would probably be to place empty gameObjects at those 15 spots, add them to some list and then spawn your objects by randomly picking one of the empty gameObjects from the list.
for example: http://stackoverflow.com/questions/2706500/how-to-generate-random-int-number-c
http://www.dotnetperls.com/list or http://msdn.microsoft.com/en-us/library/aa288453(v=vs.71).aspx
Answer by Owen-Reynolds · Sep 30, 2013 at 03:24 PM
Programming isn't super easy. In art class, best way to draw humans is to start with regular solids, pitchers, ... for practice. Best way to write a "spawn random objects" might be to program a bunch of easier stuff first. But...
Figure out a way to make and "know about" a bunch of points. Maybe 4 at first, to make testing easier. Simplest way is make a sphere Prefabs with the colliders removed. That gives you something you can place and see. Turn the meshRenderer off to hide them later (so they are really just empties.)
In the script, most people use a global Transform[] Spots;
and manually load that up in the Inspector (that's C#)
Then figure out how to spawn an object at one exact spot, like (0,0,0). Then figure out how to spawn at Spots[0].position
. Then figure out how to roll dice to pick a random spot 0 to Spots.Length-1
and spawn there. Then retest with 15 spots. Then decide if you want to repeat a point. To not repeat any is trickier -- look up shuffling.
That's my point. I think this is too difficult for your very first program$$anonymous$$g exercise. Pick something easier. You'll learn stuff. Eventually you'll work to up knowing enough for this one.
Even if someone wrote an exact solution (which is frowned on,) you'd still have to learn enough to be able to make little changes to it. Which you do by starting on easier problems.
Your answer
Follow this Question
Related Questions
how to freeze a random position? 1 Answer
How do you spawn multiple prefabs within a certain distance from each other from one spawn point? 2 Answers
Player spawn point not working. 0 Answers
Spawned prefabs not keeping their Look At funtion 2 Answers
How to prevent multiple spawns from a single spawn point? 1 Answer