using UnityEngine;
using System.Collections;

public class VisObj : MonoBehaviour {

	BoxCollider2D boxColl;
	CircleCollider2D cirColl;
	EdgeCollider2D edgeColl;
	SpriteRenderer spriteRen;
	public float fadeTime = 10f;
	public bool fadeOut = false;
	public float fade;


	// Use this for initialization
	void Start () {

		boxColl = GetComponent<BoxCollider2D> ();
		spriteRen = GetComponent<SpriteRenderer> ();
		edgeColl = GetComponent<EdgeCollider2D> ();
		spriteRen.color = new Color (0f,0f,0f,255f);
	

	}

	// Update is called once per frame
	void Update () {
		if (fadeOut == true) {
			
			spriteRen.color = Color.Lerp (new Color (0f, 0f, 0f, 0f), new Color (0f,0f,0f,0f), -0.1f);
		}
//		if (spriteRen.color == new Color (255f,255f,255f,255f) && fadeOut == true){
//			fadeOut=false;
//		}
		if (spriteRen.color.a < 255f) {
			boxColl.isTrigger = true;
			edgeColl.isTrigger = true;

		} else {
			boxColl.isTrigger = false;
			edgeColl.isTrigger = false;
		}
	}
	void OnTriggerEnter2D (Collider2D boxColl){
		if (boxColl.transform.tag == "Player") {
			spriteRen.color = new Color (0f, 0f, 0f, 0f);
			fadeOut = true;
		}
	}
}