using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class Historia : MonoBehaviour {
	public Text a;
	public int i= 0;
	public bool proximo = false;
	public AudioSource source;
	private string total = "The great nation of Brastovia is again in peril. One of our finest top secret laboratories just got shut down in order to contain a terrible outbreak." +
			";We do not know the details of what caused the outbreak or its damage extension. What we do know is that no citizen or foreigner can know of what happened, or what is about to happen." +
			";You, doctor Boris, was specially assigned to investigate the place and discover what caused the outbreak. You are expected to repair any broken machinery hindering your progress, and to interact with any computer terminal required to gather all the information needed." +
			";To keep you looking into your obligations we are also assigning one of our finest soldiers to keep an eye on you. He is authorized to provide any help requested by you and to protect you from anything harmful inside. His codename for this operation is ‘Volkov’." +
			";And since sending only two people to such a place would be considered too inhuman even to our standards, we are also sending in a dog. The dog’s name is Chitzkoi, and he is authorized to provide you both with Vodka and cuteness." +
			";Tomorrow you, Volkov and Chitzkoi will be transported into the facility. Any of the laboratory personnel is expected to be already dead, and to be killed if not. Stay focused to your job, and Brastovia will reward you immensely.;";
	
	void Start () {
		a = this.GetComponent<Text> ();
		a.text = "Hello World";
		InvokeRepeating("aumenta", 1f, .01f);
	}
	

	void Update () {
		if(!proximo)
			a.text = total.Substring (0, i);
		if (total.Length == 0)
			Application.LoadLevel (1);

	}

	void aumenta() {
		if (total [i] == ';') {
			CancelInvoke("aumenta");
			proximo = true;
		}
		i++;
	}

	void OnGUI() {
		if (proximo) {
			if(GUI.Button(new Rect(Screen.width-60,Screen.height-30, 50, 30), "Next")) {
				a.text = total.Substring (0, i);
				total = total.Substring(i);
					i = 0;
				InvokeRepeating("aumenta", 1f, .01f);
				proximo = false;
				source.Play();
			}
		}
	}
}
