using UnityEngine;
using System.Collections;

public class FadeCollider : MonoBehaviour {
	
	private GameObject playerCamera;
	public float overTime;
	
	// Use this for initialization
	void Start () {
		playerCamera = GameObject.Find ("Camera");
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	void OnTriggerEnter (Collider collision)
	{
		StartCoroutine (FixView ());
		Debug.Log ("YO");
	}
	
	IEnumerator FixView ()
	{
		float temp = playerCamera.GetComponent<Blur>().blurSize;
		Debug.Log ("1");
		float startTime = Time.time;
		Debug.Log ("2");
		while (Time.time < startTime + overTime)
		{
			Debug.Log ("3");
			playerCamera.GetComponent<Blur>().blurSize = Mathf.Lerp (temp, 0f, (Time.time - startTime) / overTime);
			Debug.Log ("4");
			yield return null;
		}
		playerCamera.GetComponent<Blur>().enabled = false;		
		GameObject.Find ("Player").GetComponent<States>().missedPills = 0;
		gameObject.SetActive(false);
		Debug.Log ("5");
	}
}
