using UnityEngine;
using System.Collections;

public class nextLevel : MonoBehaviour {

	MeshRenderer mr;
	Rigidbody rb;
	public string levelName; //enter the next level name here through inspector 
	private bool triggered;

	// Use this for initialization
	void Start () {
		mr = GetComponent<MeshRenderer> ();
		rb = GetComponent<Rigidbody> ();
		triggered = false;
	}
	
	// Update is called once per frame
	void Update () {
		if (triggered == true) {
			rb.velocity = new Vector3(0,0,0);
		}
	}

	void OnCollisionEnter (Collision col){
		if (col.transform.tag == "End") {
			Invoke("LoadLevel", 3.0f);
			mr.enabled = false;
			rb.useGravity = false;
			triggered = true;
		}
	}

	void LoadLevel (){
		Application.LoadLevel (levelName);
	}


}
