How to load a level after 30 seconds?

Hello. I am making a game that is intended for the Android and is 2D. I can’t figure out how to load a level after 30 seconds. The game is supposed to last only 30 seconds and then is suppose to take you to a different scene ( Level ).

The script I am using is

using UnityEngine;
using System.Collections;

public class Clock : MonoBehaviour {

	int hours;
	public int hours24;
	public float minutes;
	public int iMinutes;
	string fMinutes;
	string ampm;
	
	TextMesh clockText;
	
	void Start () {
		clockText = GetComponent<TextMesh> ();
		hours = 12;
		hours24 = 12;
		minutes = 01;
		ampm = "pm";
		
	}
	void Update () {
		// Build Time. Default is one minute per second.
		minutes += Time.deltaTime; 
		iMinutes = (int) minutes ;
		fMinutes = iMinutes.ToString("D2");
		
		
		if (iMinutes >= 60) 
		{
			if (hours == 12)
			{    
				hours = 0;
			}
			if (hours == 11)
			{    
				if (ampm == "am")
					ampm = "pm";
				else
					ampm = "am";
			}
			
			if (hours24 == 23)
				hours24 = 0;
			
			hours +=  1;
			hours24 += 1;
			iMinutes = 0;
			minutes = 0;
			
		}
		
		clockText.text =  fMinutes ;
	}
	
}

The counter works with Iminutes which are called minutes but count in seconds.

How can I modify the script that when the Iminutes reaches 30 a different scene loads.

All help is appreciated. If there are any questions, please ask.

If you are having such a problem:

  1. You need to learn about conditional statements in c#.
  2. You can learn to use Application.LoadLevel here.

To modify the script that, when the Iminutes reaches 30 a different scene loads.

You need to add the following ‘If’ statement inside Update() in the end :

if( iMinutes >= 30)
{ 
    //You need to pass Level index or Level name in the method.
	Application.LoadLevel(x); 
}

Now,

  1. Press ctrl+shift+b, if working in windows to open the Build Settings window.

  2. Add your scenes there. By pressing the Add Current button or drag and dropping scenes from Project window into Build Settings Window.

  3. Note the name or Integer value infront of the scene name.

  4. Replace ‘x’ in Application.LoadLevel(x); with it.

  5. For example: replace ‘x’ with “Test Scene” or simple “0”.

    Application.LoadLevel(Test Scene); Or Application.LoadLevel(0);

43041-untitled.png

When the time reaches 30 seconds, execute Application.LoadLevel()

#pragma strict
var time : float = 0;
function Start() {
time = 5;
}

 function Update () {
     if(time > 0){
        time-=Time.deltaTime;
     }else{
        Application.LoadLevel("Level1");
     }
 }