could anyone please help me add a spawn limit to this spawning script any help would be great

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

public class TimedSpawn : MonoBehaviour
{

public GameObject spawnee;
public bool stopSpawning = false;
public float spawnTime;
public float spawnDelay;

// Use this for initialization
void Start()
{
InvokeRepeating(“SpawnObject”, spawnTime, spawnDelay);
}

public void SpawnObject()
{
Instantiate(spawnee, transform.position, transform.rotation);
if (stopSpawning)
{
CancelInvoke(“SpawnObject”);
}
}
}

Please do not create unnecessary voting.
Please use code tags. https://discussions.unity.com/t/481379
Please describe what do you mean “limit” exactly and what did you try so far?

hey this is my first post and im new to unity but i tried using a counter like a list but im also new to scripting and i need help

and i mean like the spawner can only spawn a limit of 10 enemies and when one dies another one spawns

Count how many you spawn in and check whenever its 10. If it goes below 10 you just spawn a new one?

you can do it as you like:

    private bool spawnReady;
    public int actualEntitys;
    public int maxEntitys;

    void Update()
    {
       spawnEntitys()
    }

    private void spawnEntitys()
    {
        for (int i = actualEntitys; i <= maxEntitys; i++)
        {
            actualEntitys++;
            Instantiate(spawnee, transform.position, transform.rotation);
        }
    }

or:

    private bool spawnReady;
    public int actualEntitys;
    public int maxEntitys;

    void Update()
    {
        if(actualEntitys < maxEntitys)
        {
            actualEntitys++;
            Instantiate(spawnee, transform.position, transform.rotation);
        }
    }

or in a while loop:

    private bool spawnReady;
    public int actualEntitys;
    public int maxEntitys;

    void Update()
    {
        while(actualEntitys < maxEntitys)
        {
            actualEntitys++;
            Instantiate(spawnee, transform.position, transform.rotation);
        }
    }

i dont know how to get that to work? could you help me please this is the last script i would need in game

I think Terraya’s middle example does what you want, what’s the problem with that? : - )
Just put it in a new script , put that script onto Gameobject in hiearchy and fill in the public variables in inspector.(what to spawn , and how much is max (10 in your example))
although im not sure whats with the spawnReady bool in his example,… it doesnt do anything + its private so… just sayin . - )

i tried it does not work

How does it not work? Try this again. and remember that what you put this script on, in that place will all be spawned, and they will probably be all in the same position so its like there is only one of them.

public class TimedSpawn : MonoBehaviour
{
    public GameObject spawnee;
    public int actualEntitys;
    public int maxEntitys;
    void Update()
    {
        while(actualEntitys < maxEntitys)
        {
            actualEntitys++;
            Instantiate(spawnee, transform.position, transform.rotation);
        }
    }
}

yes it works how can i reference the counter into my emeny script like how can i make it --enemy on destroy i dont know???

would love to help but, what exactly do you mean?
What counter do you mean?