Efficient way of tracking number of enemies

I’m trying to keep track of the number of enemies in the scene at a time, and right now I’m using GameObject.FindGameObjectsWithTag every time an enemy is spawned (every 25 seconds or so).

I had the idea that it might be better to, rather than search for the enemy count, keep track of the enemy count in my main game controller script and tell it to increase or decrease the enemy count whenever an enemy spawns or is killed — Does anybody know if this approach would be more efficient or not?

i would say that having a single number increase by 1 evertime a new enemy is spawned and then removing 1 when the enemy is gone would be much more efficient, as your not looking for all the objects then counting them.

saying that it might not be as accurate if something interfered with it, very unlikely if everything scripted good but still its a game and we all know no matter how good a game is theres always going to tiny problems come up.

i would probably have 3 different numbers one for each enemy spawned, another for enemies killed, and then these two numbers added together to get total amount on scene.

then you have more options to do fancy stuff easier like 10 enemies killed you rule, and you could put a cap on it for amount that will be spawned and amount on screen at any time to reduce lag