try level for 3x then on the 4th go to different level

hi! im a newbie here and im trying to create this game where in you got 3 tries and after that you return to the menu.

so after 1 try, i need to load the level again. and after 3 tries. i need to load the main level.

here’s my code. it tries again but never goes back to the main menu.

	var levelToLoad: String;
        var levelToLoadgo: String;
        var beep: AudioClip;
        static var tryagain : int = 1;

		yield new WaitForSeconds(0.05);
		yield new WaitForSeconds(0.05);
		tryagain = 1;

in another script that handles time i got


at the time over mark.

Depending on how often you call that script, you might run into a conflict where tryagain was already incremented, but the Application.LoadLevel wasn’t executed yet, due to the yield.

Try rearranging your code blocks, and connect them with “else”, to make sure that only one of them gets executed, not both:

if(tryagain>3){ // you initialize tryagain already to 1, so don't use ">="
  // load main
  // restart level