How can I call IEnumerator when a boolean is true?

I’m using the IEnumerator function and have had some issues with my if statement working:

IEnumerator Spawning()
    {
        Debug.Log("Spawning being called...");
        if (GameObject.Find("FPSController").GetComponent<BoxCollide>().hitTrigger == true)
        {
            Debug.Log("CUSTOMER SHOULD SPAWN!");
            while (countStop == false) {

                yield return new WaitForSeconds(2);
                Debug.Log("Fisher Spawned!");
                counter++;
                spawnNewCharacter.SpawnCharacter();

                if (counter >= 3){
                    countStop = true;
                }

            }
        }

    }

After some debugging, it turns out that my if statement actually works. This issue is actually the IEnumerator function being called as soon as I run my game. I need a way to call this IEnumerator function only when my hitTrigger == true, but I can’t seem to get anything to work.

Thanks in advanced.

I suggest looking into Unity Manual.

this might help you.
Long story short: If you want to call the Enumerator when your hitTrigger is true then do something like this :

if(hitTigger == true)
{
    Debug.Log("Spawning being called...");
    StartCoroutine(Spawning());
}

But you should remove your first if-statement if you do so.

 IEnumerator Spawning()
     {
             Debug.Log("CUSTOMER SHOULD SPAWN!");
             while (countStop == false) {
 
                 yield return new WaitForSeconds(2);
                 Debug.Log("Fisher Spawned!");
                 counter++;
                 spawnNewCharacter.SpawnCharacter();
 
                 if (counter >= 3){
                     countStop = true;
                 }
 
             }     
     }