I am getting this error IndexOutOfRangeException: Array index is out of range.
EnemiesSpawner.Spawn () (at Assets/EnemiesSpawner.cs:18)
It keeps popping up . When do I spawn my enemies they spawn out fine to me . Here is my script :
using UnityEngine;
using System.Collections;
public class EnemiesSpawner : MonoBehaviour {
public GameObject enemy;
public Transform [] spawnPoints;
public float spawnTime = 5f;
void Start () {
InvokeRepeating("Spawn", spawnTime, spawnTime); //Calls the "Spawn" function every 10 seconds.
}
void Spawn () {
int spawnPointIndex = Random.Range (0, spawnPoints.Length); for( int spawnCount = 20 ; spawnCount > 0 ; --spawnCount )
Instantiate(enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);
}
}
↧