using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class KeyManager : MonoBehaviour
{
		private Vector3 initialPosition;
		public Transform key1;
		public Transform key2;
		public Transform key3;

		public Image imgKey1OFF;
		public Image imgKey2OFF;
		public Image imgKey3OFF;

	public Image imgKey1ON;
	public Image imgKey2ON;
	public Image imgKey3ON;

		private int activatedKey = 0;

		private int caughtKey = 0;

		public static KeyManager key;

	private GameObject player;

		void Awake ()
		{
				key = this;

		player = GameObject.FindGameObjectWithTag("Player");
		}

		void Start()
		{
		initialPosition = player.transform.position;
		}

		public Vector3 GetSpawnCoordinate ()
		{
				switch (activatedKey) {
				case 0:
						return initialPosition;
				case 1:
						return key1.position;
				case 2:
						return key2.position;
				case 3:
						return key3.position;
				}
				return initialPosition;
		}

		public void SetActiveKey (int key)
		{	
				activatedKey = key;
		}	

		public int GetActivatedKey ()
		{
				return activatedKey;
		}

		public bool openDoorOk()
		{
			return caughtKey == 3;
		}

		public void increaseCaughtKey ()
		{
				caughtKey++;
				switch (caughtKey) {
				case 1:
						imgKey1OFF.enabled = false;
						imgKey1ON.enabled = true;
						break;
				case 2:
						imgKey2OFF.enabled = false;
						imgKey2ON.enabled = true;
						break;
				case 3:
						imgKey3OFF.enabled = false;
						imgKey3ON.enabled = true;
						break;
				}
		}
}
