#How to Create a Counter that increases when something dies?

1 messages · Page 1 of 1 (latest)

real silo
#

I was wondering how I should go about making this death script increase a counter on another script so that when all enemies are dead the level will end.

wild hatch
#
  1. In your scene manager script add a condition(counter var) to the sceneManager.LoadScene(yourSceneName)
    All of the code must be put in the update fnc

  2. Access the counter variable from the scene manager script and add an counter ++ before calling Die()

exotic creek
#

There are multiple ways to handle that. You could have a LevelManager or GameManager and on death accessing a function inside them to keep track of the deaths.
gameManager.Died();
and inside the GameManager script

public float enemiesInLevel;

public void Died(){
  enemiesInLevel--;
  if(enemiesInLevel <= 0){
    ChangeLevel();
  }
}
#

Or you could add onto a death counter and end the level after a specific number.