- Home /
 
               Question by 
               risinghell09 · Sep 01, 2013 at 10:35 PM · 
                prefabplayerrandomspawn  
              
 
              How do I spawn a random prefab?
I want to spawn a random prefab from my list. The prefabs are players such as a Ninja or a Cyborg. So when the game starts, a player prefab from my list is spawn that the player can control. So every time the player dies, another prefab from the list will be spawned. So it will go on and on, but I'm not sure how I can accomplish this. Can someone please help me?
               Comment
              
 
               
              Answer by fherbst · Sep 01, 2013 at 10:40 PM
Take a look at Random.Range.
 Transform[] prefabs;
 
 void SpawnANewOne() {
   int index = Random.Range(0, prefabs.Count);
   Transform randomPrefab = prefabs[index];
   Instantiate(randomPrefab);
 }
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                