c# - 仅在一个 Boss 死亡后生成 Boss 敌人

标签 c# unity3d

在我的 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:

Coins shown in Text ui

现在我制作了一个游戏 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/

相关文章:

unity3d (2d!) - 相机以玩家为中心,但永远不会超过 "map"边界

android - Unity 2020 无法将 android APK 更新到 API 级别 29

c# - 在游戏对象上运行一次脚本

unity3d - 带着色器图的双面着色器

c++ - 通过类库从 Unity IL2CPP 项目访问 Windows 10 功能

c# - MailMessage 在 outlook 中将字符串作为正文发送而没有换行符

c# - 哪些 Unity 类型可以为空?

c# - 从 ContentControl 中的按钮触发命令?

c# - udp收不到任何数据

javascript - SignalR 2.2 客户端未收到任何消息