- Home /
Question by
nimaldev · Oct 07, 2016 at 10:03 PM ·
prefabrandomgeneration
Prefab Random Generation
I have 24 different Prefabs in a 2D world, they have a bottom and a ceiling, and I want to generate them i a random order directly behind each other. How I can do this? I have no idea.
EDIT: With bottom and ceiling , is meant that it's like a room
Comment
You have to clarify a bit more on what you are trying to achieve. Do you want to instantiate 24 prefabs in a straight line - in random order - in front of each other? Are the prefabs rooms?
I have different prefabs (the amount doesn't matter, it could be 20 oder 200) and i want make an infinit runner. So i want the prefabs to spawn in a random order. And i don't know how to do this, have I to create a new empty object and this is the spawnpoint or how do I do this.
To create a random prefab:
GameObject[] prefabs;
void SomeFunction(){
GameObject o = Instantiate(prefabs[UnityEngine.Random.Range(0,prefabs.Length)]);
o.transform.position= Vector3.zero; /*Replace with the wanted position*/
}