using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class LevelChanger : MonoBehaviour {

	float LevelFinish = 0.0f;
	public string SceneName;
	public Texture Background;

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		if(LevelFinish>0.0f) {
			LevelFinish -= Time.deltaTime;
			if(LevelFinish <= 0.0f) {
				SceneManager.LoadScene(SceneName);
			}
		}
	}

	void OnTriggerEnter(Collider other)
	{
		if (other && other.transform == Player.Instance.transform)
		{
			LevelFinish = 3.0f;
		}
	}

	void OnGUI()
	{
		//GUI.skin.font = TextFont;
		GUIStyle Style = GUI.skin.GetStyle("Label");
		Style.fontSize = 50;
		Style.alignment = TextAnchor.MiddleCenter;

		Style.normal.textColor = Color.white;

		if(LevelFinish>0.0f) {
			Rect TextLocation2 = new Rect(Screen.width * 0.5f - 200, Screen.height * 0.25f - 50, 400, 100);
			GUI.DrawTexture(TextLocation2, Background);
			GUI.Label(TextLocation2, "Well done");
		}
	}
}
