How to make a Game Over when too many enemies are onscreen?

The small game I’m making has fire as enemies, and the player needs to put the fire out before it gets too out of hand.
I need a function to count how many GameObjects of fire are onscreen so if there’s ever more than, hypothetically, 5 fires onscreen, then it will trigger a game over. Is there something I could use to do this?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpawnManager : MonoBehaviour
{
    public GameObject enemies;
    private float startDelay = 1;
    private float spawnInterval = 4;
    public float xSpawnRange;
    public float bottomSpawnRange;
    public float topSpawnRange;

    // Start is called before the first frame update
    void Start()
    {
        InvokeRepeating("SpawnEnemies", startDelay, spawnInterval);
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    void SpawnEnemies()
    {
        Vector3 spawnPos = new Vector3(Random.Range(-xSpawnRange, xSpawnRange), Random.Range(bottomSpawnRange, topSpawnRange), 0);
        Instantiate(enemies,spawnPos, Quaternion.identity);
    }
}

Usually one increments a counter when the enemy appears, decrements it when it is killed.

Then a GameManager or similar construct can observe this number and make decisions.

This construct (counting coins, enemies, deaths, whatever) is the same in many games.

If the above is insufficient to get you going, hurry to look at some tutorials for games that have this ultra-common construct. It will almost certainly involve thinking about more than just code.

Two steps to tutorials and / or example code:

  1. do them perfectly, to the letter (zero typos, including punctuation and capitalization)
  2. stop and understand each step to understand what is going on.

If you go past anything that you don’t understand, then you’re just mimicking what you saw without actually learning, essentially wasting your own time. It’s only two steps. Don’t skip either step.

Imphenzia: How Did I Learn To Make Games: