- Home /
C# Random spawn from an array
Hello,
I have this problem I cant seem to figure out. I have an array with frozen food in it. The idea is that the food falls over the Y axis and the player defrosts it by clicking on it.
I want that the food I put in the array gets spawned at a random place in a box collider. And only on the X axis.
How do I do this?
You use `GameObject.Instantiate()` to spawn the object. You need to pass it a prefab, and the second parameter is the position you want it. Choose a random position within the box with `Random.Range()`.
And I strongly recommend doing some basic tutorials before you start working on a game:
http://unity3d.com/learn/tutorials/modules/beginner/scripting/instantiate
Your answer
Follow this Question
Related Questions
Problem with random generated objects(intersects objects) 1 Answer
Randomly Initiate Cubes - Prevent Same Position 0 Answers
Distribute terrain in zones 3 Answers
Choosing a random location out of a list for an object to spawn at. 1 Answer
How to make an object/prefab choose between multiple given positions to spawn into? 1 Answer