P
P
PurgaBot2021-12-08 16:51:44
Unity
PurgaBot, 2021-12-08 16:51:44

How to spawn any number of objects by prefab?

I need to spawn a RANDOM number of prefab objects on each new scene start, and have them in the list.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Farawa, 2021-12-08
@Farawa

[SerializedField] private GameObject prefab;

Start()
{
var rand = UnityEngine.Random.Range(5,50);
for(int i=0;i<rand;i++)
{
    GameObject go = Instantiate(prefab);
}
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question