using UnityEngine;
using System.Collections;

public class TryAgainController : MonoBehaviour {

    public float text1Wait;
    public float text2Wait;
    public bool restartGame = false;

    TextController text1;
    TextController text2;

    private bool actionEnabled = false;

	// Use this for initialization
	void Start () {
        text1 = GameObject.Find("Text1").GetComponent<TextController>();
        text2 = GameObject.Find("Text2").GetComponent<TextController>();

        StartCoroutine(FadeInText());
    }
	
	// Update is called once per frame
	void Update () {
        if (actionEnabled && Input.GetKeyDown(KeyCode.Space)) {
            Application.LoadLevel("main");
            if (restartGame) ChapterManager.Reset();
            ChapterManager.StartChapter();
        }

        if (actionEnabled && Input.GetKeyDown(KeyCode.Escape)) {
            Application.Quit();
        }
	}

    IEnumerator FadeInText() {
        yield return new WaitForSeconds(text1Wait);
        text1.FadeIn();

        yield return new WaitForSeconds(text2Wait);
        actionEnabled = true;
        text2.FadeIn();
    }
}
