我想让我的敌人在自己旋转的同时使用'spawn'从顶部出现。
但是我收到了这个错误:
IndexOutOfRangeException: Array index is out of range.
spawnScript.addEnemy () (at Assets/Scripts/spawnScript.cs:21)
以下是我的脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class spawnScript : MonoBehaviour {
public Transform[] spawnPoints;
public GameObject enemy;
public float spawnTime = 5f;
public float spawnDelay = 3f;
// Use this for initialization
void Start () {
InvokeRepeating ("addEnemy", spawnDelay, spawnTime);
}
void addEnemy() {
// Instantiate a random enemy.
int spawnPointIndex = Random.Range(0, spawnPoints.Length);
Instantiate (enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);
}
// Update is called once per frame
void Update () {
}
}