How to detect number of certain objects in the scene?

I am trying to make the game detect when there is less than one of a certain game object, it will spawn after a time. I cant use tags for it, as the object and its variant i am not wanting to spawn at this point both have the same tags. I am trying to use a list but i really don’t know how to use it, so if someone could tell me how to use it OR give me a better solution, that would be appreciated. Here is my code, the code i am trying to use is at the bottom, and I’m calling it in the Cow Spawn method. I’d appreciate explaining what code is being given to me as well!

using System.Collections.Generic;
using NUnit.Framework;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UIElements;
using static UnityEngine.Rendering.DebugUI.Table;


public class SpawnManager : MonoBehaviour
{
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    public GameObject[] cowPrefab;
    private PlayerControl PlayerControl;
    public GameObject Plane;
    PointTracker  pointTracker;
     GameObject Cow;
    CreatureMovement creatureMovement;
    public List<GameObject> cows;



    void Start()
    {
        Cow = GameObject.Find("Cow(Clone)");
        pointTracker = GameObject.Find("PointTracker").GetComponent<PointTracker>();
        PlayerControl = GameObject.Find("UFO").GetComponent<PlayerControl>();
        creatureMovement = GetComponent<CreatureMovement>();
        
            InvokeRepeating("CowSpawn", 1, 5);

        

        InvokeRepeating("PlaneSpawn", 1, Random.Range(10,15));

        
    }

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

        }
    }

    void CowSpawn()
    {
        if (PlayerControl.gameOver == false && pointTracker.score < 10)
        {
            int randomNumber = Random.Range(0, 2);
            float angle = randomNumber == 0 ? 90f : -90f;
            Vector3 spawnPosition = new Vector3(Random.Range(-11f, 11f), 1.5f, -1.39f);
            Instantiate(cowPrefab[Random.Range(0, cowPrefab.Length)], spawnPosition, Quaternion.Euler(0, angle, 0));

            
        }

        if (PlayerControl.gameOver == false && pointTracker.score >= 10 && pointTracker.score < 24)
        {

            int randomNumber = Random.Range(0, 2);
            float angle = randomNumber == 0 ? 90f : -90f;
            Vector3 spawnPosition = new Vector3(Random.Range(-11f, 11f), 1.5f, -1.39f);
            Instantiate(cowPrefab[Random.Range(0, 3)], spawnPosition, Quaternion.Euler(0, angle, 0));
        }

        if(PlayerControl.gameOver == false && pointTracker.score >= 24)
        {
            StartCoroutine(CreaturePhase());
        }
    }

    void PlaneSpawn()
    {
        if (pointTracker.score < 8)
        {
            float yRangeDown = 8.0f;
            float yRangeUp = 9.8f;
            int randomNumber = Random.Range(0, 2);
            float angle = randomNumber == 0 ? 90f : -90f;

            Vector3 spawnRange = new Vector3(31.3f, Random.Range(yRangeDown, yRangeUp), -1);
            Vector3 spawnRangeLeft = new Vector3(-31.3f, Random.Range(yRangeDown, yRangeUp), -1);



            if (PlayerControl.gameOver == false)
            {
                GameObject newPlane = Instantiate(Plane, spawnRange, Quaternion.Euler(0, angle, 0));

                if (angle == 90)
                {
                    newPlane.transform.position = spawnRangeLeft;
                }

            }
        }
    }

    public IEnumerator CreaturePhase()
    {
        if (cows == null && creatureMovement.creaturePhase == true)
        {
            yield return new WaitForSeconds(5);
            Vector3 spawnPosition = new Vector3(Random.Range(-11f, 11f), 1.5f, -1.39f);
            int randomNumber = Random.Range(0, 2);
            float angle = randomNumber == 0 ? 90f : -90f;
            Instantiate(cowPrefab[Random.Range(0, 3)], spawnPosition, Quaternion.Euler(0, angle, 0));
        }

    }

}

Multiple tags per GameObject:

var list = new List<GameObject>();
list.Add(go);
list.Remove(go);

That’s the basics.

All you need to do to keep track of your objects is to put them in a list, or a dictionary where the key is what you would have used as a label (ie a string, a component Type, or an enum).

Call Add on Instantiate, call Remove in OnDestroy. And in order to learn when an object runs its OnDestroy, the spawning script would do this:

private List<GameObject> list = new();
void TheSpawnMethod()
{
    var go = Instantiate("name");
    list.Add(go);
    var notify = go.AddComponent<NotifyDestroy>();
    notify.TellMeWhenYouDie += OnObjectDestroyed;
}

void OnObjectDestroyed(go) => list.Remove(go);

And the NotifyDestroy component:

public class NotifyDestroy : MonoBehaviour
{
    public event Action<GameObject> TellMeWhenYouDie;
    void OnDestroy() => TellMeWhenYouDie?.Invoke(gameObject);
}

If you still need help you could assign each object a parent during creation and use transform.childCount to get the total amount

// create a new variable
public Transform SpawnParent;
//change
int randomNumber = Random.Range(0, 2);
float angle = randomNumber == 0 ? 90f : -90f;
Vector3 spawnPosition = new Vector3(Random.Range(-11f, 11f), 1.5f, -1.39f);
Instantiate(cowPrefab[Random.Range(0, cowPrefab.Length)], spawnPosition, Quaternion.Euler(0, angle, 0));
//to
int randomNumber = Random.Range(0, 2);
float angle = randomNumber == 0 ? 90f : -90f;
Vector3 spawnPosition = new Vector3(Random.Range(-11f, 11f), 1.5f, -1.39f);
Instantiate(cowPrefab[Random.Range(0, cowPrefab.Length)], spawnPosition, Quaternion.Euler(0, angle, 0), SpawnParent);
// then call
SpawnParent.childCount when you want the count e.g.
if (SpawnParent.childCount > 0)