几天前我在这里遇到了一个导致无限生成的脚本问题。我解决了这个问题,但现在还有另一个问题。故障又回来了,但是以一种奇怪的方式。它似乎仍然存在spawn脚本的问题。目前它产生一波敌人,等待5秒,然后产生另一组,并宣布"波3"。它应该产生一个波,声明"波1",等待它们被杀死,然后产生两个波并声明"波2"
我使用了一些调试日志来尝试获取它。这是结果: 0spawn 1 1spawn 2 2spawn 3 3spawn 3message 1 2 3 4 五 6
Spawn脚本
static var waveNumberMessage : boolean = false;
function Start()
{
StartCoroutine("CoStart");
}
function CoStart() : IEnumerator
{
while (true)
yield CoUpdate();
}
function CoUpdate(){
if (deathcounter.timeToSpawn == true){
if (spawnCount == 0 && deathcounter.timeToSpawn == true){
spawnCount = deathcounter.enemySpawnCount;
}
while(spawnCount >= 0)
{
var target= Instantiate(targetPrefab, transform.position, transform.rotation);
target.rigidbody.AddForce(Vector3.right * (150 + waveCounter * 10));
spawnCount = spawnCount - 1;
Debug.Log(waveCounter + "spawn");
yield WaitForSeconds (5);
if (spawnCount == 0){
waveCounter = waveCounter + 1;
Debug.Log(waveCounter);
deathcounter.timeToSpawn = false;
waveNumberMessage = true;
}
}
}
}
function OnGUI()
{
if(waveNumberMessage == true)
{
GUI.Box(Rect((Screen.width/2 - 100),(Screen.height/2 - 40),200,80),"Wave: " + waveCounter);
Invoke("HideNumberMessage", 3.0f);
Debug.Log(waveCounter + "message");
}
}
function HideNumberMessage()
{
waveNumberMessage = false;
}
死亡计数器脚本
static var enemyDeathCount = 0;
static var enemySpawnCount = 1;
static var timeToSpawn : boolean = true;
function Update () {
if(enemyDeathCount % 3 == 0 && enemyDeathCount != 0){
timeToSpawn = true;
enemySpawnCount = enemySpawnCount + 1;
}
}
有什么想法吗?