utkdub
utkdub

Reputation: 274

Spawning Boss enemy only after when one boss is dead

In my 2d game I have a concept of gold and copper coins as follows:

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

now I have made a game obj boss spawner which has a script attached to it as follows:

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;
            }
        }


    }
}

so according to the condition ..if its true in script one boss out of 2 should spawn..and it is working fine too.

But what I want is that when I kill the boss the coins process should go on and when again condition (that %2 one becomes true) the boss (any one acording to coins) should spawn

But It is only spawning for one time and then after that when I kill the boss and again condition of coin aac. to script becomes true the boss is not spawning in the game !

Now how to remove this problem ?

Upvotes: 3

Views: 600

Answers (1)

Keiwan
Keiwan

Reputation: 8301

This happens because you never reset bossSpawned to be false so that a new boss can be spawned. You could add a method

public void Reset() {
    bossSpawned = false;
}

and call this whenever a boss dies.

Upvotes: 2

Related Questions