仅在一个 Boss 死亡后生成 Boss 敌人
Spawning Boss enemy only after when one boss is dead
在我的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 in UI
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 应该生成..它也工作正常。
但是我想要的是当我杀了boss时coins
进程应该继续并且什么时候再次出现条件(那个%2一个变为真)老板(根据硬币的任何一个)应该产卵
但是它只会生成一次,然后当我杀了 boss 之后又出现了 coin aac 的情况。脚本变为真 Boss 不会在游戏中生成!
现在如何解决这个问题?
发生这种情况是因为您从未将 bossSpawned
重置为 false
以便生成新的 Boss。你可以添加一个方法
public void Reset() {
bossSpawned = false;
}
并在 boss 死亡时调用它。
在我的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 应该生成..它也工作正常。
但是我想要的是当我杀了boss时coins
进程应该继续并且什么时候再次出现条件(那个%2一个变为真)老板(根据硬币的任何一个)应该产卵
但是它只会生成一次,然后当我杀了 boss 之后又出现了 coin aac 的情况。脚本变为真 Boss 不会在游戏中生成!
现在如何解决这个问题?
发生这种情况是因为您从未将 bossSpawned
重置为 false
以便生成新的 Boss。你可以添加一个方法
public void Reset() {
bossSpawned = false;
}
并在 boss 死亡时调用它。