using UnityEngine;
using System.Collections;

public class LightToggle : MonoBehaviour {
	private enum State {
		Deaf,
		Blind
	}
	
	[SerializeField] private State myState;
	private const State INITIAL_STATE = State.Deaf;
	[SerializeField] private bool  useDistance = false;
	[SerializeField] private float minimumDistance = 10;
	private float initialLightIntensity;
	
	[SerializeField] private bool toggleRenderer;
	[SerializeField] private bool toggleLight;
	[SerializeField] private bool toggleAudio; 
	
	private void Awake() {
		bool isDeaf = (myState == INITIAL_STATE);
		if (renderer != null && toggleRenderer)  renderer.enabled = isDeaf;
		if (audio != null    && toggleAudio)     audio.mute       = !isDeaf;
		if (light != null && toggleLight) {
			light.enabled = isDeaf;
			initialLightIntensity = light.intensity;
		}
	}
	
	private void Update() {
		if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift)) {
			if (renderer != null && toggleRenderer) renderer.enabled = !renderer.enabled;
			if (light != null    && toggleLight   ) light.enabled    = !light.enabled;
			if (audio != null    && toggleAudio   ) audio.mute       = !audio.mute;
		}
		
//		if (useDistance && light != null) light.intensity = initialLightIntensity * Mathf.Lerp(0.5f, 1.5f, Mathf.PingPong(Time.time, 2));
		
//		if (usarDistancia) {
//			float lerped = Mathf.Clamp01((distanciaMinima - Vector3.Distance(transform.position, Jugador.posicion)) / distanciaMinima);;
//			if (light != null && light.enabled) {
////				light.intensity = lerped;
//			}
//			if (renderer != null && renderer.enabled) {
//				Color tempColor = renderer.material.color;
//				tempColor.a     = lerped;
//				renderer.material.color = tempColor;
//			}
//		}
	}
}
