- Home /
 
randomly call prefab
hii everyone i want to call prefabs randomly .how can i generate this. here is my code
var Prefab1 : GameObject; var Prefab2 : GameObject; var Prefab3 : GameObject; var Prefab4 : GameObject; var Prefab5 : GameObject;
thanks
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by StephanK · Apr 16, 2011 at 08:41 AM
You should put the prefabs into an array. So you can do this:
var prefabs : GameObject[];
int rand = Random.Range(0,5);
GameObject.Instantiate(prefabs[rand]);
 
               
               In general if you end up with variable names like prefab1, prefab2 and so on in 99% of the cases you are better off using an array.
Your answer