using UnityEngine;
using System.Collections;

public class TileManager : MonoBehaviour 
{

	public bool whiteActive = true;
	//private GameObject[] tiles;
	private GameObject[] whiteOnly;
	private GameObject[] blackOnly;

	// Use this for initialization
	void Start () 
	{
		//tiles = GameObject.FindGameObjectsWithTag("Filtro");
		whiteOnly = GameObject.FindGameObjectsWithTag("OnlyWhite");
		blackOnly = GameObject.FindGameObjectsWithTag("OnlyBlack");
	}
	
	// Update is called once per frame
	void Update () 
	{
		if (Input.GetButtonDown("Jump"))
		{
			ChangeActive();
		}

		if (whiteActive) 
		{
//			foreach (GameObject tile in tiles)
//			{
//				tile.GetComponent<SpriteRenderer>().renderer.enabled = true;
//				tile.GetComponent<SpriteRenderer>().color = new Color (0.9f, 0.9f, 0.9f, 0.5f);
//			}
			foreach (GameObject white in whiteOnly)
			{
				white.GetComponent<SpriteRenderer>().renderer.enabled = true;
				white.GetComponent<Collider2D>().collider2D.enabled = true;
			}
			foreach (GameObject black in blackOnly)
			{
				black.GetComponent<SpriteRenderer>().renderer.enabled = false;
				black.GetComponent<Collider2D>().collider2D.enabled = false;
			}
		}
		else
		{
//			foreach (GameObject tile in tiles)
//			{
//				tile.GetComponent<SpriteRenderer>().renderer.enabled = true;
//				tile.GetComponent<SpriteRenderer>().color = new Color  (0.1f, 0.1f, 0.1f, 0.5f);
//			}
			foreach (GameObject black in blackOnly)
			{
				black.GetComponent<SpriteRenderer>().renderer.enabled = true;
				black.GetComponent<Collider2D>().collider2D.enabled = true;
			}
			foreach (GameObject white in whiteOnly)
			{
				white.GetComponent<SpriteRenderer>().renderer.enabled = false;
				white.GetComponent<Collider2D>().collider2D.enabled = false;
			}
		}
	}

	public void ChangeActive()
	{
		if (whiteActive)
		{
			whiteActive = false;
		}
		else
		{
			whiteActive = true;
		}

		Debug.Log ("OnlyBlack");
	}

}