- Home /
Spawn Meteors At random location C#
I am wanting to make a script that you can drop a prefab of your meteor on and then set like an average distance or something then when you hit the play button it spawns them randomly around the area. I would somewhat like to be able to use an array that way it can be set the amount of meteors to spawn.
Please Help.
Answer by AlucardJay · May 04, 2013 at 10:58 PM
http://docs.unity3d.com/Documentation/ScriptReference/Random-insideUnitSphere.html
http://wiki.unity3d.com/index.php?title=Which_Kind_Of_Array_Or_Collection_Should_I_Use?
array variable
number of meteors variable
meteor prefab
set array size to the number of meteors variable
loop for number of meteors
instantiate prefab into current loop array position
randomize position using random insideUnitSphere multiplied by a random minimum maximum distance
rinse and repeat
Your answer
![](https://koobas.hobune.stream/wayback/20220613101533im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Help with an error urgent 2 Answers
Converting to C# 1 Answer