我在游戏中工作,我只是想弄清楚如何修复我的敌人产卵者。我的目标是产生一种特定的行为,即产生轻松的敌人x20(或任何没有。)然后是中等的敌人,然后是随机的轻松,中等和硬敌的无尽的产卵。我也希望每个产卵之间有一个延迟或休息1-2秒所以它看起来不像是敌人在彼此之上发送垃圾邮件
目前我只有简单和中等的敌人产卵,并且它的结束并不是无限的,除了我得到一个数组超出范围错误
我们非常感谢您的帮助,并提前感谢您 这是我的代码:
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);
}
}