The easiest way is to execute a check once an enemy dies to see if there are other enemies left. If not, new scene is loaded. You should of course make sure to keep track of your enemies by e.g. filling a list on startup or similar.
function Update() {
var enemies = GameObject.FindWithTag("Enemy") //find gameobjects with the tag "enemy" (you must therefore tag the enemies with "enemy"
if(enemies == null){ //if no gameobjects with the tag "enemy" are found
Application.LoadLevel(2)//change scene
}
}
If so, what script would i put this in and where to attach it?
That would work, but I would suggest using InvokeRepeat(). So instead of using Update() which calls every 33ms (I think) call it every second with InvokeRepeat(). This will save a lot of processing power,
Edit. @ what, Glockenbeat suggested is the best method probably. You would need to have a manager that has a function that is called, when an enemy dies. Each enemyScript, should know when it dies. It should also know its manager (use GetComponent) then when enemy does, in the enemy script, tell the manager an enemy has died. Lower your enemyCounter. If enemy count == 0, load new scene.
Thanks for the help, i don’t need the power for this game uhm, i figured it out but i cannot tag an object with “Enemy”, i go to where it says ‘Untagged’ and try to tag it but no where i can write my own tag? any ideas, it works as i tested it with “Respawn”
Another easy way you could do this is to have a static variable in your enemy script. On Start you would increment this int. Then when each ones dies you can decrement it and when it hits 0 load you new scene. Keep in mind you should set it to 0 if you exit the game scene and restart without killing all the enemy’s.
public static int enemyCount=0;
public void Start(){
enemyCount++;
}
public void Die(){
enemyCount--;
if (enemyCount==0){
//Load new scene here
}
}
Update happens every frame. If you’re running at 30FPS then that’d be every 33ms, but if you’re running at 60FPS it’s every 16.6ms, and so on (frame time in ms = 1000 / frames per second).