using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;


public class Gate : MonoBehaviour 
{

	//public GameObject gate;
	public GameObject collectThemAll;
	public GameObject congratulations;
	
	// Update is called once per frame
	void Update () 
	{
		/*
		if (PlayerPrefs.GetString ("island1item1") == "taken" && PlayerPrefs.GetString ("island1item2") == "taken" && PlayerPrefs.GetString ("island1item3") == "taken" && PlayerPrefs.GetString ("island1item4") == "taken" && PlayerPrefs.GetString ("island1item5") == "taken" && PlayerPrefs.GetString ("island1item6") == "taken") 
		{
			gate.SetActive (false);
			joya.SetActive (false);

		} 
		else 
		{
			gate.SetActive (true);
			joya.SetActive (true);
		}
		*/
	}


	void OnTriggerEnter2D(Collider2D other)
	{
		if(other.gameObject.tag == "Player")
		{
			Debug.Log ("win trigger GATE");

			if (PlayerPrefs.GetString ("world1item1") == "taken" && PlayerPrefs.GetString ("world1item2") == "taken" && PlayerPrefs.GetString ("world1item3") == "taken" && PlayerPrefs.GetString ("world1item4") == "taken" && PlayerPrefs.GetString ("world1item5") == "taken" && PlayerPrefs.GetString ("world1item6") == "taken") 
			{
				//gate.SetActive (false);
				collectThemAll.SetActive (false);
				StartCoroutine (Winner ());
				Debug.Log ("win trigger GATE");
			}
		} 
		
	}


	IEnumerator Winner()
	{
		yield return new WaitForSeconds (1f);
		congratulations.SetActive (true);
		yield return new WaitForSeconds (2f);
		SceneManager.LoadScene("Map");
	}



}
