【发布时间】:2017-11-11 16:37:01
【问题描述】:
我想让我的敌人在旋转时使用“spawn”从顶部出现。
但是我收到了这个错误:
IndexOutOfRangeException:数组索引超出范围。 spawnScript.addEnemy () (在 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 () {
}
}
【问题讨论】: