Is it possible to have one script to call upon levels please help!!

Hey everyone I was wondering if anyone could help me or point me in the right direction. I have a script for my game for loading a specific scene when clicking on the correct object. When I click on the right object, I have it go to a win screen. When I click on the wrong object, I have it go to a lose screen. Each of those scenes have a button for next level or reset level. I have a script for loading the next level as shown:

#pragma strict

function Start_Game_Button () 
	Application.LoadLevel("Level 1");

My question is do I have to make that script for every scene to load the next level/scene (ex 1 2 3 4 5 etc)? Or is there a way to make a script that will keep going to the next level without me having to write the script:

	Application.LoadLevel("Level 1");
	Application.LoadLevel("Level 2");
	Application.LoadLevel("Level 3");
	Application.LoadLevel("Level 4");

if anyone can help me or point me in the right direction I would greatly appreciate it. Thank you.

You could make a function in your script which moves to the next level by using the index that the scene has in your build settings.

If you read this page SceneManager you can see that SceneManager.LoadScene (Note that SceneManager.LoadScene has replaced Application.LoadLevel) can pick a scene from the index that it has in the build settings.

This means that if you keep track of the index of the scene you are in, you could simply do:

function LoadNextLevel(){

Edit: As Toon_Werawat mentioned in another similar question, you should be able to use

SceneManager.LoadScene(SceneManager.GetActiceScene().buildIndex + 1);

Which would save you from keeping track of the current index in a static variable.

Ok thanks for your help! I did try what you suggested as Toon_Werawat stated, but since my index includes a “Lose Scene” and “Win Scene”, it kinda messes up the buildindex counting up. I found this:

The only way to accomplish this that I have found is to make multiple game over scenes even if they look the same.

Then position them in the build index underneath each level. So "level 1" is above "Level1GameOverScene" and "Level 2" is above "Level2GameOverScene" and so on.

Then add the script that says SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex -1); onto The "Try again" text for example in your GameOver scene.

And attach another script onto the thing that causes the game to be over that says - SceneManager.LoadScene (SceneManager.GetActiveScene ().buildIndex + 1);

This way the scenes are relying working with each other as long as they are positioned correctly in the build index. This is the only way I can think of that is easy but I can almost guarantee that someone experienced can find a much easier way using code I've never even heard of.

I hope this helps others in my situation but if not, good luck finding a solution to your problem. :)

however, I feel that it is not efficient, and I am sure there is a better way. Is it possible to have a win and lose screen load up within a level scene? That way it is not considered a “scene”. Like how in flappy bird when you die, a popup comes up saying game over, despite still saying in the same scene. Does anyone know? Any help I would greatly appreciate it.