I want to continually spawn objects from an array of spawnSpots. If I make the spawn spots single game objects and copy/paste the instantiate I can get it to work. But when I use a transform array for the spawn spots i get the error “IndexOutOfRangeException: Array index is out of range.”
How do i repeat the for loop without it starting at the end of the last iteration?
I have tried setting i =0; in a couple of places but that does not appear to be the answer.
Thanks for helping me understand coding better.
using UnityEngine;
using System.Collections;
public class Spawn : MonoBehaviour {
public GameObject bubblePrefab;
public GameObject bubbleClone;
public Transform[] spawnSpots;
public int maxCount;
public bool doSpawn = true;
public float minTime ;
public float maxTime ;
// Use this for initialization
void Start () {
StartCoroutine (spawnOverTime());
}
IEnumerator spawnOverTime()
{
while (doSpawn == true)
{
int size = spawnSpots.Length;
int i = 0;
for ( i = 0; i <= size ; i++)
{
bubbleClone = Instantiate(bubblePrefab, spawnSpots_.position , spawnSpots*.rotation) as GameObject ;*_
* }*
* } *
* }*
}