Try to find ways where you can reuse as much as possible. If you have a huge amount of scenes which all are presented in chronological order then create a function which you can call from your game when conditions are met for a level load. Overloads are handy as well.
// Automatically increment and loop on exceed
static function LoadLevel () {
var level : int = Application.loadedLevel+1;
level = level%Application.levelCount-1;
Application.LoadLevel(level);
}
// Load level by string
static function LoadLevel (level : String) {
Application.LoadLevel(level);
}
// Load level by int
static function LoadLevel (level : int) {
Application.LoadLevel(level);
}
So calling ClassName.LoadLevel(); would load next level in your listed scenes. Thanks to the overload (a bit redundant in the example), you can also call ClassName.LoadLevel(“Menu”) to load up a scene called Menu. Before a level load happens you can execute anything you want, for instance show a summary and outro. What’s beautiful in this case is also that if you decide to change the flow of a scene ending you’ll have everything in one place instead of scattered scripts for each scene.
Functions are the solution for many in other cases repeated tasks. If something will happen repeatedly, try to make it a general solution which you can access from anywhere in your workflow.
Are you asking whether LoadLevel has to be in a special script? (Maybe because of an example in the docs?)
LoadLevel is just a normal command. You can put it anywhere. For example, if the playerScript sees you’ve died, you could call LoadLevel right there, to restart.