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

public class Global_Place_Sc : MonoBehaviour {

    
	public float PlayerHealth
    {
        set {
            GameObject GlobalData = GameObject.Find("Global_Data");
            GlobalData.GetComponent<Data_Holder>().PlayerHealth = value; }
        get {
            GameObject GlobalData = GameObject.Find("Global_Data");
            return GlobalData.GetComponent<Data_Holder>().PlayerHealth; }
    }

    
	public float PlayerScore
    {
        set {
            GameObject GlobalData = GameObject.Find("Global_Data");
            GlobalData.GetComponent<Data_Holder>().PlayerScore = value; }
        get {
            GameObject GlobalData = GameObject.Find("Global_Data");
            return GlobalData.GetComponent<Data_Holder>().PlayerScore;  }
    }

    
    public string PlayerName
    {
        get {
            GameObject GlobalData = GameObject.Find("Global_Data");
            return GlobalData.GetComponent<Data_Holder>().PlayerName;  }
    }
	public GameObject Health_1;
	public GameObject Health_2;
	public GameObject Health_3;

    public GameObject Global_Data;



	// Use this for initialization
	void Start () {
		PlayerHealth = 3;
		PlayerScore = 0;

		Health_1 = GameObject.Find ("Health_1");
		Health_2 = GameObject.Find ("Health_2");
		Health_3 = GameObject.Find ("Health_3");
        Global_Data = GameObject.Find("Global_Data");


	}
	
	// Update is called once per frame
	void Update () {

        
	
		if (PlayerHealth <= 0) {
            SceneManager.LoadScene(2);
		}

		switch (Mathf.RoundToInt(PlayerHealth)) {
		case 0:
			{
				Health_1.SetActive (false);
				Health_2.SetActive (false);
				Health_3.SetActive (false);
				break;
			}
		case 1:
			{
				Health_1.SetActive (true);
				Health_2.SetActive (false);
				Health_3.SetActive (false);
				break;
			}
		case 2:
			{
				Health_1.SetActive (true);
				Health_2.SetActive (true);
				Health_3.SetActive (false);
				break;
			}
		case 3:
			{
                Health_1.SetActive (true);
				Health_2.SetActive (true);
				Health_3.SetActive (true);
				break;
			}

		default:
			break;
		}

	}

	public void RestartLevel(){
		SceneManager.LoadScene (0);
	}
}
