Change level after ''X'' seconds

Hello can some one help me, I am devloping a game in which you have to visit diferent places in a ‘‘X’’ amount of time I am using this code but I don’t know why it dosen work…

function Start(){

yield WaitForSeconds(30);

Application.LoadLevel(1);

yield return new WaitForSeconds(30);
Application.LoadLevel(2);

}

I haven’t tested this code, but I’m at least 90% sure this would be the right way to do it.

     //Level you want to load, this can be adjusted in the inspector
        var levelIndexToLoad : int = 1 
        var timeToWait : float = 30.0f;
        function Start(){
    
            LoadLevelAfterTime();
        }
    
        function LoadLevelAfterTime(){
            yield WaitForSeconds(timeToWait);
            Application.LoadLevel(levelIndexToLoad);
            levelIndexToLoad++;
        }

Now the reason you want to do it this way is because the Start(), Update(), and FixedUpdate() functions can NOT be ran as a coroutine. And inorder to use the WaitForSeconds() function it must be called within a coroutine. Let me know if this script works for you now. All you should need to do is attach it to an object in the scene, select the time to wait, and the level index in the inspector pane of that object, and after the set amount of time it should load that level without any problems. You would only need one copy of this per scene that you want to achieve this effect on.

use DontDestroyOnLoad() to load any level
And this script is put in a level is load once

static var loadAlevel = 1;

function Awake()
{
    DontDestroyOnLoad(this);
    StartWait ();
}

function StartWait ()
{
    yield WaitForSeconds(30);
    Application.LoadLevel(loadAlevel);
    loadAlevel ++;
}