# can't instantiate different objects

I'm trying to instantiate different prefabs at once. But couldn't figure out how. I tried to use Random.Range method but didn't worked for me. It instantiates only one of the prefabs. I want it to instantiate all of the prefabs.

• It's not clear from your question what you tried and where your mistake might be. Can you show us the code you wrote, explain what you expect it to do and what it does instead? Nov 4 '20 at 11:46

You haven't explained nearly enough about what you're trying to do, but here are some examples:

public List<GameObject> prefabs;

//Instantiate one of each prefab
public void InstantiateAll() {
foreach (var prefab in prefabs) {
Instantiate(prefab);
}
}

//Create the given number of instances from random prefabs
public void InstantiateRandom(int count) {
for (int i = 0; i < count; i++) {
int index = UnityEngine.Random.Range(0, prefabs.Count);
var prefab = prefabs[index];
Instantiate(prefab);
}
}

• Please don't answer questions when they don't explain enough about what they are trying to do. Convince the author to clarify their question through an edit and then answer the question when you actually know what help they need. Nov 4 '20 at 18:25
• @Philipp That's hardly worth a downvote over. I addressed the two things he mentioned in his post, "instantiate all of the prefabs" and "use Random.Range". A more thorough question is definitely better, but these are easy answers that I would expect to mostly or completely solve whatever simple problem he's having. Nov 4 '20 at 19:39