using UnityEngine;
using System.Collections;

public class InvisObj : 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> ();
		cirColl = GetComponent<CircleCollider2D> ();
		spriteRen = GetComponent<SpriteRenderer> ();
		spriteRen.color = new Color (255f,255f,255f,0f);
	}
	
	// Update is called once per frame
	void Update () {
		if (fadeOut == true) {
			//fade = Mathf.SmoothDamp (255f, 0f,ref fadeSpeed, fadeTime);
			spriteRen.color = Color.Lerp(spriteRen.color,new Color (255f, 255f, 255f, 0f), 0.05f);
		}
		if (spriteRen.color == new Color (255f,255f,255f,0f) && fadeOut == true){
			fadeOut=false;
		}
	}
	void OnTriggerEnter2D (Collider2D boxColl){
		if (boxColl.transform.tag == "Player" || cirColl.transform.tag =="Player" || edgeColl.transform.tag =="Player") {
			spriteRen.color = new Color (255f, 255f, 255f, 255f);
			fadeOut = true;
		}
	}
}
