How to change Scene once all player characters are no longer active.

Hi guys! I am new to programming but I somehow managed to stumble my way in to making an almost complete game. For the last stage of my game, the players are forced to betray each other. The game turns from a 2d side scroller 4 player Coop to a 2D 4 way versus game where my friends try to kill each other.

I am trying to get the game to change scene to a “Game Over” picture once all players die. To do this, I plan to use something like GetComponentsInChildren().GetLength(0); in order to count how many player characters are active in the scene but I cannot get this to work. The player characters are child objects of a parent object called “characterselectvs”. So I guess my questions are the following:

  1. How do I implement the GetComponentsInChildren().GetLength(0); ?
  2. Where do I put the code or script to count the active children and then change scene?

Good day.

You have multiple ways to count things, and getcomponentsinchildern is the worst XD, well not the worst, but is designed for this. Or each player is a component?

What are the players? Objects? Then just create a Tag for them and use

void Update ()
   GameObject ListOfPlayers = GameObject.FindObjectsWithTag("TheTag");
  if (ListOfPlayers.length == 0)

Or you can make all the players send a message to a central script every X seconds, and if the central script does not recieve any signal for 2X seconds it means thay are all dead.

Or you can create a publuc array with all the players from the begginig, and when the array is empty, it emans they are all dead.

OR if you know the maximum nuber of players, every time a playter dies, substract 1 from a counter

And thousands more ways…

TRy to look for tutorial videos to get the “developing thinking” and will no need to make ths questions :smiley: