Let’s say you have a list with 5 gameObjects, how do i instantiate each object a number times, let’s say the first object is instantiated 5 times, then the next object 3 times, then the next object 6, and so on with a 1 second delay between each instantiation?
I did that this way - the most simple I think. I created a list of 5 prefabs, and a second list of 5 ints. The first list “prefabs” stores prefabs which will be turned into objects. Each index of the second list “numberOfObjects” stores information on how many instances of the prefab with the same index have to be created. Both lists are serialized, so fill them in the inspector. For simplicity, there is no error checking. Here is the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Nokia4410 : MonoBehaviour
{
[SerializeField]
List<GameObject> prefab;
[SerializeField]
List<int> numberOfObjects;
void Start(){
StartCoroutine(Spawner());
}
IEnumerator Spawner(){
WaitForSeconds delay = new WaitForSeconds(1f);
for(int i = 0; i < prefab.Count; i++){
for(int j = 0; j < numberOfObjects*; j++){*
_ Vector3 randomPosition = Random.insideUnitSphere * 5f;_
_ Instantiate(prefab*, randomPosition, Quaternion.identity);*_
* yield return delay;*
* }*
* }*
* }*
}
this is what i was looking for, thanks a lot!