using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Down : MonoBehaviour {
	public GameObject player;
	public Touch_move move;
	public string st;
	public Text txt;
	public GameObject text_frame;
	public GameObject laser;
	public bool x;

	IEnumerator PlayText(){

		foreach (char c in st) {

			txt.text += c;
			yield return new WaitForSeconds (0.2f);
		}

		if (txt.text.Length == st.Length) {
			text_frame.SetActive (false);
			move.pause = false;
			if (x) {
				if (laser) {
					laser.SetActive (true);

				}
				Invoke ("open_door", 5);
			}
		}

	}

	void OnMouseDown(){
		x = true;
		if (player.transform.position.x == move.pos.x) {
			move.pause = true;
			st = "this door opens a finger print";
			txt.text = "";
			text_frame.SetActive (true);

			StartCoroutine ("PlayText");

		}
	}
	void OnMouseUp(){

		x = false;
		if (laser) {
			laser.SetActive (false);
		}
		CancelInvoke ("open_door");
	}

	void open_door(){

		gameObject.GetComponent<Animator> ().enabled = true;
		Destroy (laser);
		gameObject.GetComponent<Collider> ().enabled = false;
	}
}
