How to make something happen when all of one type of enemies are destroyed by bullets.

I want to have green enemy set a sprite of a key active when all green enemies are dead while having red ones destroyed to do something else. Would I tag all green ones and say something like
Update {
If (gameobject.tag(“greenenemies” == null ) {

And where would I put this code on an empty game object or my character or my key. Thanks in advance.

Based on what you mentioned in your question, a simple way to do this would be to check your scene for enemies with certain tags when an enemy is killed; there isn’t a need to check every object in the scene each frame with Update(). Something like this:

//when an enemy's health is <= 0
if (GameObject.FindGameObjectsWithTag("green").Length == 0)
    //do something

else if (GameObject.FindGameObjectsWithTag("red").Length == 0)
    //do something else

There are obviously things you could do to optimize this code, but this is simple and should get you the results you want.

You could have an enemy spawner increment a counter if you have a variable amount of enemies or enemies that are constantly spawning in. If the number stays the same, you could either search for the enemies, drag and drop them into a list and use the list count, or just input the number.

Then on the enemy you could decrement that number in the OnDestroy() method or if you have a list you don’t have to do that. Just put in the OnDestroy method a check to see if the number / list count is <= 0.

If it is, you do whatever you want to do when they’re all dead.