敌人产卵系统。我希望简单的敌人首先产生然后产生媒介,之后我想要强硬的敌人产生不间断。我想要它无尽的产卵请

时间:2016-06-24 21:38:47

标签: c# unity3d system unity5

  • 目前我有产卵系统产生Easy然后中等敌人但是我得到阵列超出范围错误并且它只产生了4个敌人。我想要x20 easy(或一般数字)x20中等然后随机(简单,中等和硬敌)。

这是我的代码:

using UnityEngine;
using System.Collections.Generic;
using UnityEngine.UI;

public class Test : MonoBehaviour
{

public GameObject[] enemy; 

public Transform[] spawnPoints;         

private float timer = 2;


int index = 0 ;

int wave = 0;

List <GameObject> EnemiesList = new List<GameObject>();

private int enemyCount=20;


void Update()
{
    timer -= Time.deltaTime;

    if (timer <= 0 && wave < 6)
    {
        timer = 3;

        if (wave != 0 &&  wave % 2 == 0)
        {
            index ++ ;
        }

        EnemySpawner();

        wave++;
    }

}

void Spawn ()
{

    for (int i = 0; i<enemyCount;i++)
    {
        Invoke("EnemySpawner" , i + 2);
    }
}

void EnemySpawner ()
{
    int spawnPointIndex = Random.Range (0, spawnPoints.Length);

    GameObject InstanceEnemies= Instantiate ( enemy[index] , spawnPoints[spawnPointIndex].position , spawnPoints[spawnPointIndex].rotation) as GameObject;

    EnemiesList.Add(InstanceEnemies);

}

public void Remove (GameObject anything)
{
    EnemiesList.Remove (anything);
}

}

1 个答案:

答案 0 :(得分:1)

我认为您需要将enemyCount变量设置为数组的长度。如果阵列中有15个敌人且enemyCount仍为20,该怎么办?对我来说听起来像是一个IndexOutOfRangeException。