Enemy Spawn script not continuing level

I have a enemy spawn script that spawns enemies and increases its level every 20 enemies that appear. So on level 4 i have an special enemy that appears but after you destroy the enemy the level does not advance and no more enemies are created here is my script

var isON: boolean = true;
var level: int;

function Update () {

	if (isON){
	transform.Translate(Vector3(direction * speed * Time.deltaTime,0,0));
	if (Time.time > lastSpawn + nextSpawn){
		Instantiate(enemy, transform.position, Quaternion.identity);
		level = manager.ShipCounter();
		manager.ShipCounter();
		lastSpawn = Time.time;
		nextSpawn = Random.Range(1.0,3.0 - (.2 * level));
		}
	}
	
	if (level == 4 && isON == true){
		isON = false;
		Instantiate(Enemyred, Vector3(0,8,2), Quaternion.identity);
		}
}

I tried multiple approaches as removing the “isON = false;” but that just adds more than 1 enemy in the game and floods my gamescreen. Be great if anybody can help.

P.S. (IsON) is a trigger where i can either turn the spawner off or on during something situations i want to turn it back on after i destroy a specific enemy

The script you pasted does not have an area where isON goes back to true value after the redEnemy is spawned… To have it work you will need to set it to true either through redEnemy (on destruction or whenever you want it) or through a timer if you want the other enemy types to spawn even though redEnemy is still on the screen.

I think the problem can be in the
manager.ShipCounter();
I mean probably it remains in “4” so when you turn “isON” true again, you gonna have “isOn && level=4” making the script turnig isON=false