using UnityEngine;
using System.Collections;

public class SplashBehaviour : MonoBehaviour {

	public GameObject eventSheet;
	public string message;

	private GameObject sceneFader;
	
	bool waitActive = false;
	bool canSwitch = false;

	void Start()
	{
		eventSheet = GameObject.FindGameObjectWithTag("EventController");
		message = eventSheet.GetComponent<EventSheet>().myOpeningLine();

		sceneFader = GameObject.Find("SceneFader");;
	}
	
	void FixedUpdate ()
	{
		if(!waitActive)
		{
			StartCoroutine(Wait(53));
		}
		if(canSwitch)
		{
			sceneFader.GetComponent<SceneFadeInOut>().EndScene();
			Application.LoadLevel(1);
		}
	}

	IEnumerator Wait(float time)
	{
		waitActive = true;
		yield return new WaitForSeconds (time);
		canSwitch = true;
		waitActive = false;
	}
}
