how to Instantiate one prefab and then have it stop?

I want it to work so that if the player reaches the startzone or is past it spawn one minion then stop
checking if the player is in the startZone or not.
it’s not doing that it’s spawns as many minions as it can if I am in the area or past the start of it.

using UnityEngine;
public class Flying2EyeEnemy : MonoBehaviour
{
    public Transform startZone;
    public GameObject minions;
    public Transform minionSpawn;
    public Transform player;
    public bool spawnMinions;

    void Start()
    {

    }

    void Update()
    {
        if (player.position.x >= startZone.position.x)
        {
            spawnMinions = true;
            if (spawnMinions)
            {
                SpawnMinion();
            }
            else
            {
                spawnMinions = false;
            }
        }
    }
    void SpawnMinion()
    {
        Instantiate(minions, minionSpawn.position, minionSpawn.rotation);

    }
}

Good day.

You are having logic problems… Try to simulate in your brain what the code does when the spawnMinions becomes true… wil lsee have no sense, it never goes false, so it never stop spawinig…

you r not using corretly the bools and cheks… I supose you want this

 void Update()
 {
    if ( player.position.x >= startZone.position.x)
     {
       if( !spawnMinions )
        {
        spawnMinions = true;
        SpawnMinion();
        }
     }
    else
    {
     spawnMinions = false ;
    }
 }

REally, dont copy/paste the code.,… you need to understand what are you doing. This is a very very simple case, you will need to do things like this SOO MANY TIMEES , so if dont iunderstand this, you should think again about developing and coding…

Bye!