在我的 2d 游戏中,我有一个金币和铜币的概念如下:
when normal enemies die ..they drop a random gold or copper coin. Now when player picks it the coins value gets added to the
PlayerPrefs
file and is also shown inUI
as follows:
现在我制作了一个游戏 obj boss spawner,它附有如下脚本:
public class BossSpawner : MonoBehaviour {
private int GoldLimitChk,CopperLimitChk;
public GameObject[] BossPrefab;
public bool bossSpawned;
private BossHealthManager boss1;
private Boss2HealthManager boss2;
// Use this for initialization
void Start () {
bossSpawned = false;
boss1 = FindObjectOfType<BossHealthManager> ();
boss2 = FindObjectOfType<Boss2HealthManager> ();
}
// Update is called once per frame
void Update () {
GoldLimitChk=PlayerPrefs.GetInt ("CurrentMoney");
CopperLimitChk=PlayerPrefs.GetInt ("CurrentMoneyCopper");
Debug.Log ("Gold:" + GoldLimitChk);
Debug.Log ("Copper:" + CopperLimitChk);
if (GoldLimitChk % 2 == 0) {
if (bossSpawned==false) {
Instantiate (BossPrefab [1], transform.position, transform.rotation);
bossSpawned = true;
}
}
if (CopperLimitChk % 2 == 0) {
if (bossSpawned==false) {
Instantiate (BossPrefab [0], transform.position, transform.rotation);
bossSpawned = true;
}
}
}
}
所以根据条件..如果它在脚本中为真,则应该产生 2 个中的 1 个 boss..并且它也工作正常。
但是我想要的是,当我杀了老板时,硬币
过程应该继续,并且当条件再次出现时(%2 变为真)老板(根据硬币的任何一个)应该产卵
但它只生成一次,然后当我杀死 boss 并再次出现硬币 aac 的情况时。脚本变为真 Boss 不会在游戏中生成!
现在如何解决这个问题?
最佳答案
发生这种情况是因为您从未将 bossSpawned
重置为 false
以便生成新的 Boss。你可以添加一个方法
public void Reset() {
bossSpawned = false;
}
每当 boss 死亡时调用它。
关于c# - 仅在一个 Boss 死亡后生成 Boss 敌人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41519267/