- Home /
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
you should be setting isON to true, when Enemyred is destroyed, then your script will run as usual as before.
Wherever you are destroying EnemyRed try using getComponent to access the script mentioned above and changed the value of isON by a setter. That should do the trick if you mean to keep spawning after EnemyRed is dead.
Answer by Shmulzious · May 10, 2014 at 09:45 AM
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.
Answer by LazyDog_Rich · May 10, 2014 at 11:40 AM
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
$$anonymous$$aybe adding some condition like if enemyRed destroyed level = 5 isOn = true
Thanks i'm trying actually figure out a script that was the question i was asking how to continue after i destroy it
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
enemy spawn and in game time counter 1 Answer
Trap Door Question 1 Answer
Enemy AI Help? 1 Answer