Disable load new level until all enemies are dead

I am making a simple top down 2d dungeon crawler RPG and I want it to be set so that the player cant load into a new scene until all enemies are dead. I have it set up with an empty object with a box collider 2d and when the player collides with that it loads into the scene i have set it to load to. But i dont want to the player to be able to load into the new scene till they’ve killed all the enemies in that scene. Im thinking it might be something like
if(other.gameObject.tag == "Enemy") { //then somehow disable load new level }
but i dont know much about scripting so im probably WAY off lol.
Thanks for any help :slight_smile:

Hi;
u can simply create an int variable and by killing each enemy increase its value by 1 ;
then with a simple if statement check if the variable is for example equal to 10 then Active the object that has the collider on it witch player can go to next level with it;

well each enemy has its own script and u cant create this function in enemy script cause that script will be destroy when the enemy die ;

so u need to create another script in your scene attache it to a Empty GameObject and name it for example “Manager” then create a function in it witch do the things like this :

    public int NeedEnemyDiedToGoNextScen;
    public int CurrentEnemyDied;
    public GameObject NextLevelLoaderObject;
    public void CheckPlayerCanGoNextLevel()
    {
        CurrentEnemyDied += 1;

        if (CurrentEnemyDied >= NeedEnemyDiedToGoNextScen)
        {
            NextLevelLoaderObject.SetActive(true);

        }



    }

so each time this function “CheckPlayerCanGoNextLevel” is called it will increase the value by 1 and then check if its enough to active the object;
So now the only thing u need is calling this function witch should happen when an enemy die so u simply call it in your enemy script or where ever u kill an enemy u call this way :

        GameObject.FindObjectOfType<Manager>().CheckPlayerCanGoNextLevel();

Hope u solve it ;

I implemented this code and it’s good. I can lend another example of my code if you like?