using UnityEngine;
using System.Collections;

public class ItemManager : MonoBehaviour 
{
	public bool itemCollected = false;

	public string itemKey;
	public GameObject collectableW1Item1;
	public GameObject collectableW1Item2;
	public GameObject collectableW1Item3;
	public GameObject collectableW1Item4;
	public GameObject collectableW1Item5;
	public GameObject collectableW1Item6;

	//***********************************************

	void Start () 
	{
		NotificationCenter.DefaultCenter().AddObserver(this,"WinLevel"); // cambiar o quitar
		//NotificationCenter.DefaultCenter().AddObserver(this, "CollectItem");

		//Debug.Log(itemKey);


		if (PlayerPrefs.GetString("world1item1") == "taken")
		{
			collectableW1Item1.SetActive(false);
		}

		if (PlayerPrefs.GetString("world1item2") == "taken")
		{
			collectableW1Item2.SetActive(false);
		}

		if (PlayerPrefs.GetString("world1item3") == "taken")
		{
			collectableW1Item3.SetActive(false);
		}

		if (PlayerPrefs.GetString("world1item4") == "taken")
		{
			collectableW1Item4.SetActive(false);
		}

		if (PlayerPrefs.GetString("world1item5") == "taken")
		{
			collectableW1Item5.SetActive(false);
		}

		if (PlayerPrefs.GetString("world1item6") == "taken")
		{
			collectableW1Item6.SetActive(false);
		}
	}
		

	void WinLevel(Notification notificacion)
	{
		if (!collectableW1Item1.activeInHierarchy && !collectableW1Item2.activeInHierarchy && !collectableW1Item3.activeInHierarchy && !collectableW1Item4.activeInHierarchy && !collectableW1Item5.activeInHierarchy && !collectableW1Item6.activeInHierarchy)
		{
			ItemSave ();
			Debug.Log ("items were saved");
		}
	}



	public void ItemSave()
	{
		if (collectableW1Item1.activeInHierarchy == false) 
		{
			PlayerPrefs.SetString ("world1item1", "taken");
		}

		if (collectableW1Item2.activeInHierarchy == false) 
		{
			PlayerPrefs.SetString ("world1item2", "taken");
		}

		if (collectableW1Item3.activeInHierarchy == false) 
		{
			PlayerPrefs.SetString ("world1item3", "taken");
		}

		if (collectableW1Item4.activeInHierarchy == false) 
		{
			PlayerPrefs.SetString ("world1item4", "taken");
		}

		if (collectableW1Item5.activeInHierarchy == false) 
		{
			PlayerPrefs.SetString ("world1item5", "taken");
		}

		if (collectableW1Item6.activeInHierarchy == false) 
		{
			PlayerPrefs.SetString ("world1item6", "taken");
		}
	}



}
