![](/img/trans.png)
[英]For some reason my zombies tries to go to 0 0 0 instead of the player and I don't know why
[英]For some reason my code is spawning in my zombies when it is not supposed to and I don't know why
这个脚本应该在我的僵尸中以波浪的形式产生。 我的问题是它不应该在第二波中产生,我不知道为什么会这样做。 我知道enemyCount 不是0,因为当游戏运行时我检查并确认它超过0。是否有人可以查看代码并告诉我有什么问题。 我什么都没找到。 谢谢!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Waves : Zombie
{
public int enemyCount;
public GameObject behemoth;
public GameObject runner;
public GameObject zombie;
private int xPos;
private bool HasSecondWaveRan;
private bool HasThirdWaveRan;
public int enemyCount2 = 1;
// Start is called before the first frame update
void Start()
{
for (int i = 0; i < 10; i++)
{
xPos = Random.Range(31, -14);
Instantiate(zombie, new Vector3(xPos, 0.4f, 6), Quaternion.identity);
enemyCount = enemyCount + 1;
}
for (int i = 0; i < 3; i++)
{
xPos = Random.Range(31, -14);
Instantiate(runner, new Vector3(xPos, 0.4f, 6), Quaternion.identity);
enemyCount = enemyCount + 1;
}
}
// Update is called once per frame
void Update()
{
if (enemyCount == 0)
{
StartCoroutine(SecondWave());
HasSecondWaveRan = true;
}
if (enemyCount2 == 0)
{
StartCoroutine(ThirdWave());
HasThirdWaveRan = true;
}
}
IEnumerator SecondWave()
{
if (HasSecondWaveRan == false)
{
yield return new WaitForSeconds(5.0f);
for (int i = 0; i < 5; i++)
{
xPos = Random.Range(31, -14);
Instantiate(runner, new Vector3(xPos, 0.4f, 6), Quaternion.identity);
}
for (int i = 0; i < 20; i++)
{
xPos = Random.Range(31, -14);
Instantiate(zombie, new Vector3(xPos, 0.4f, 6), Quaternion.identity);
}
enemyCount2 = 25;
enemyCount = 1;
HasSecondWaveRan = true;
}
}
IEnumerator ThirdWave()
{
if (HasThirdWaveRan == false)
{
yield return new WaitForSeconds(5.0f);
for (int i = 0; i < 5; i++)
{
xPos = Random.Range(31, -14);
Instantiate(runner, new Vector3(xPos, 0.4f, 6), Quaternion.identity);
}
for (int i = 0; i < 20; i++)
{
xPos = Random.Range(31, -14);
Instantiate(zombie, new Vector3(xPos, 0.4f, 6), Quaternion.identity);
}
HasThirdWaveRan = true;
}
}
}
我通过将敌人计数预设为 1 来修复它。我可以假设问题是更新发生在敌人计数更新(滞后)之前
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.