I’ve found some solutions similar to what I am looking for but they don’t quite answer my question.
The following is the criteria I’m trying to meet:
-
I’m trying to spawn an array of game objects with a time delay between each.
-
The number of items in the array is given by a variable that updates as the number of items in the array changes
-
I’m calling the method in update because the items can’t spawn at start, it is only after a given time delay they will start spawning
-
They must stop spawning once every element in the array has spawned
-
They must spawn in order element[0], element[1], etc.
I tried to do something like the following:
private float countdown;
private float timeBetweenSpawns;
private int counter = 0; // this updates depending on the number of items given to the array
void Start()
{
countdown = timeBetweenSpawns;
}
void Update()
{
for(int i = 0; i < counter; i++)
{
if(countdown <= 0)
{
Instantiate(array*, transform.position, quaternion.identity);*
countdown = timeBetweenSpawns;
else
{
countdown -= time.deltatime;
}
}
the main issue with this is that it keeps repeating, and they do seem to spawn out of order at times, I’m not sure why I can’t really find a pattern to the mayhem.
I then tried to do something like this:
for (int i = 0; i < clueCounter; i++)
{
StartCoroutine(WaitABit());
Instantiate(colors*, transform.position, Quaternion.identity);
_}*
IEnumerator WaitABit()
{
yield return new WaitForSeconds(5);
}
this spawns them in the order they are supposed to be spawned but because I have to call it in update the game objects are constantly spawning. I tried adding in some conditions that will only allow it to spawn once but nothing I’m doing seems to work and it just ends up messing with the order they spawn in.
Anyone have some tips for me to try, this seems like a simple concept but it’s giving me some grief.