Here is my code
using UnityEngine;
using System.Collections;
public class SpawnScript : MonoBehaviour {
public GameObject[] objects;
public float spawnMin = 1f;
public float spawnMax = 2f;
// Use this for initialization
void Start () {
Spawn();
}
void Spawn()
{
Instantiate(objects[Random.Range(0, objects.GetLength(0))],
new Vector3(transform.position.x + 20, transform.position.y, 0) ,
Quaternion.identity);
Invoke("Spawn", Random.Range(spawnMin, spawnMax));
}
}
but I am getting this error.
IndexOutOfRangeException: Array index is out of range.
SpawnScript.Spawn () (at Assets/Script/SpawnScript.cs:19)
SpawnScript.Start () (at Assets/Script/SpawnScript.cs:12)
any ideas to what I am doing wrong?