######写了一个关于随机生成怪兽的脚本,结果运行报错
这是我的代码
public GameObject[] monster;
public Transform[] monsterpos;
private int index;
// Use this for initialization
void Start () {
InvokeRepeating("MonsterCreat", 5, 5);
}
// Update is called once per frame
void Update () {
int index = Random.Range(0, 3);
}
void MonsterCreat()
{
Instantiate(monster[Random.Range(0, 3)], monsterpos[index]);
}
运行结果及报错内容
IndexOutOfRangeException: Array index is out of range.
MonsterCreats.MonsterCreat () (at Assets/Jiaoben/MonsterCreats.cs:21)
出现了这个报错