using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour {
	
	static private Player myInstance;
	static public Vector3 position {
		get {
			return myInstance.myTransform.position;
		}
	}
	
	private Transform myTransform;
	private AudioListener myAudioListener;
	
	private float escapeCounter = 0;
	[SerializeField] private TextMesh escapeTextMesh;
	[SerializeField] private TextMesh escapeTextMeshShadow;
	
	private void Awake() {
		myInstance = this;
		myTransform = transform;
		myAudioListener = this.GetComponentInChildren<AudioListener>();
		
		RenderSettings.fog      = false;
//		myAudioListener.enabled = false;
		
		escapeTextMesh.gameObject.SetActive(false);
	}
	
	private void Update() {
		if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift)) {
			RenderSettings.fog = !RenderSettings.fog;
//			Debug.Log("RenderSettings.fog=" + RenderSettings.fog);
//			myAudioListener.enabled = !myAudioListener.enabled;
		}
		
		if (Input.GetKeyDown(KeyCode.Escape)) {
			escapeTextMesh.gameObject.SetActive(true);
			escapeCounter = 0;
		}
		
		if (Input.GetKey(KeyCode.Escape)) {
			if (escapeCounter < 1) {
				escapeCounter += Time.deltaTime;
				escapeTextMesh.text = "Quitting in " + (1 - escapeCounter).ToString("0.00");
				escapeTextMeshShadow.text = escapeTextMesh.text;
			}
			else {
				escapeTextMesh.text = "Quitting...";
				escapeTextMeshShadow.text = escapeTextMesh.text;
				Application.Quit();
			}
			
		}
		
		if (Input.GetKeyUp(KeyCode.Escape)) {
			escapeTextMesh.gameObject.SetActive(false);
		}
	}
}
