i have this code that spawns enemies is “waves” and the enemies get stronger by each wave.

using UnityEngine;
using System.Collections;

public class Spawner : MonoBehaviour {
 public GameObject Object;
 public float SpawnLimit = 100;
 public int Chance = 100;
 public float Multiplier = 2;
 public bool Enemy;
 public float DamageLimit = 10;
 public int Count = 0;
 public float DmgModLimit = 3;
 public float CurDmgMod = 0;
 public float HealthLimit = 200;
 public float HealthModLimit = 7;
 public float CurHealthMod = 0;
 public float LootModLimit = 60;
 public float CurLootMod = 0;
 public Texture2D VictorySplash;
 public int nextBuff;
 public GameObject WaveIndicator;
 //pruvate
 private GameObject PauseM;
 private PauseManager PM;
 private string Tgt;
 void Start()
 {
 PauseM = GameObject.Find("PauseMenu");
 PM = PauseM.GetComponent<PauseManager>();
 if(Enemy)
 Tgt = "E_Creep";
 if(!Enemy)
 Tgt = "N_Creep";
 }
 // Update is called once per frame
 void Update () 
 {
 if(!PM.isPasued)
 {
 WaveIndicator.guiText.text = "Wave: " + Count + "/" + SpawnLimit;
 if(Count < SpawnLimit)
 {
 if(Random.Range(0, Chance) == 1)
 {
 Count++;
 if(Chance > 120)
 Chance--;
 if(Count >= nextBuff)
 {
 nextBuff += 10;
 if((DamageLimit*(Count/SpawnLimit))* Multiplier <= DmgModLimit)
 CurDmgMod += (DamageLimit*(Count/SpawnLimit))* Multiplier;
 else
 CurDmgMod += DmgModLimit;
 if((HealthLimit*(Count/SpawnLimit))* Multiplier <= HealthModLimit)
 CurHealthMod += (HealthLimit*(Count/SpawnLimit))* Multiplier;
 else
 CurHealthMod += HealthModLimit;
 if((LootModLimit*(Count/SpawnLimit)) * Multiplier <= LootModLimit)
 CurLootMod += (LootModLimit*(Count/SpawnLimit)) * Multiplier;
 else
 CurLootMod += LootModLimit;
 Debug.Log("LastBuf: " + nextBuff);
 }
 GameObject Clone = Instantiate(Object, transform.position, transform.rotation) as GameObject;
 Clone.GetComponent<CreepAI>().RecieveBuff(Enemy, CurDmgMod, CurHealthMod, CurLootMod);
 }
 }
 }
 if(Count >= SpawnLimit && !GameObject.FindWithTag(Tgt))
 {
 PM.isPasued = true;
 Screen.lockCursor = false;
 gameObject.AddComponent("GUITexture");
 gameObject.guiTexture.enabled = false;
 gameObject.guiTexture.texture = VictorySplash;
 gameObject.transform.position = new Vector3(.5f, .5f , 9999);
 gameObject.guiTexture.enabled = true;
 if(Input.GetKeyUp(KeyCode.Space))
 {
 Application.LoadLevel(0);
 }
 }
 }
}

This however results in random spawning where enemies are somethings placed on top of each other. this way also has each wave only containing 1 enemy. this method is affected by framerates, it will work faster or slower based on framerate. is there a way to modify this to make it spawn X enemies per wave for N waves, and have at each wave a buff code run to make is successive wave stronger, and have it not affected by framerate.

to set time maybe that can help but I’m not sure

float lastFrameTime = 0.0f;

if(lastFrameTime < Time.time + (1/24f)) 

from

I’m stumbled on serching other

hope can serve

You could have an array of enemies, all activated when the waves starts and when an enemy is killed you do not destroy him you respawn him or deactivate him until next wave.

You can declare a strength variable that increase on death.

This way on next wave, the exact same enemy is stonger.

The good point of this is efficiency, you do not destroy the enemy, hence you do not call the garbage collector, you do not instantiate new object and as a result you do not mess too much with the memory management.

Concerning enemies spawned on top of each other, use a limited amount of spawn points (like 5) with a waiting time. This way your enemy is already gone before you respawn a new one.

I think in the if where the enemy is spawned, mybe loking the link U can understand
sorry but c# is not in my hand
perhaps using yeld could be better

this is how i solved the problem: it works perfectly,

if(!GameObject.FindWithTag(Tgt) && SpawnedOfWave == EnemiesPerWave)
 {
 BuffWave((float)CurWave/(float)MaxWave);
 LastWave = CurWave;
 CurWave++;
 SpawnedOfWave = 0;
 }
 if(CurWave > LastWave)
 {
 if(SpawnedOfWave < EnemiesPerWave)
 {
 if(LastFramTime < Time.time - (SpawnRate))
 {
 SpawnEnemy();
 SpawnedOfWave++;
 }
 }
 }