How to switch to next level after completeing the task in current level

Hi dudes, I am designing a game with 3 Levels for example if we have 10 enemies in our first level and once its completed we have to switch to the next level and so on. Here my doubt is in coding part once i complete my task by destroying my enemies in Level 1 how can jump to next level in this also i can load my next level by using "Application.LoadLevel("name of scene")" but the thing is how to identify that my enemies are destroyed and to loaded the next level automatically Please help me


Do you have all those levels in different scenes. if you have it as different scenes means first add all those scenes when you build the project. when you hit build it shows a button name as ADD CURRENT.first you just hit it and add all those levels of your project.after you add this it'll appear like this,

Scene1 Name - 0 Scene2 Name - 1 Scene3 Name - 2

you'll get like this,if you want to move 2nd scene after killing those enemies means just use Application.LoadLevel(1), and move 3rd scene means use Application.LoadLevel(2).

see this link

if you're not using different scene you cant use Application.LoadLevel.

Simple and enjoy.

         // Loads the level with index 0

           Application.LoadLevel (0);

          // Load the level named "HighScore".

           Application.LoadLevel ("HighScore");

This function loads level by its index. You can see the indices of all levels using the File->Build Settings... menu in Unity. Before you can load a level you have to add it to the list of levels used in the game. Use File->Build Settings... in Unity and add the levels you need to the level list there.

Well, in order to detect when all the enemies are destroyed (in order to load the next level), you'll need to keep some kind of counter to keep track of how many enemies are left. That way, when the counter reaches zero, you know you have no enemies left, and you can advance to the next level.

I recently gave an answer to a very similar question here. Since the script is almost exactly what you need, just replace "cannon" with "enemy" and you should be good to go. Oh, and you'll also need a way to keep track of what level you're on, so you that you can advance to the next one.

function Start()
application.LoadLevel(“levelName”);// switches to this level name on start
// OR you can use this
Application.LoadLevel (0);// which loads the scein in the index order

This is a very old question, but I will answer anyway’s to help anyone struggling to understand as of yet. Here are a list of steps.

  1. Add a few variables to your script(in this case a Boolean, a Float and a second Float).
  2. Use a Boolean value to detect if all the enemies are killed in a level.
  3. Use an if statement to find out if all the enemies are killed using one of the float values.(this will probably make more sense in the code provided)
  4. Load a level if all enemies are killed.
  5. Repeat Steps 2-4 in level 2 and 3.
  6. With that second float I told you to add your going to create a list of enemies killed.

Script is in C#.

using UnityEngine;
using System.Collections;

public class switchLevel : Monobehavior 

public bool allEnemiesKilled;
public float enemiesInLevel = 10.0f;
public float enemiesKilled;

void Awake ()
DontDestroyOnLoad(this); //Ensures we don't lose our variables, playerPrefs work good for this too
void Update () 
if(enemiesKilled < enemiesInLevel ) //if enemies kill is greater than or equal to the amount of enemiesInLevel
allEnemiesKilled = true; //allEnemiesKilled is equal to true
if(allEnemiesKilled = true)  //if allEnemiesKilled is equal to true, then load the level specified