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

public class GameController : MonoBehaviour {
    public Image life1;
    public Image life2;
    public Image life3;
    public Text gameOver;
    public Text restart;
    private int vida = 3;

	[SerializeField] private Vector3 respawnPos;
	[SerializeField] private Transform plyer;
	[SerializeField] private Animator anim;
	PlayerController pc;
	Rigidbody2D rg;

	void Start () {
       
        if (PlayerPrefs.HasKey("life"))
        {
            vida = PlayerPrefs.GetInt("life");
            if (vida == 2)
            {
                life1.enabled = false;
                restart.enabled = true;
                Destroy(restart, 2f);
            }
            else if (vida == 1)
            {
                life1.enabled = false;
                life2.enabled = false;
                restart.enabled = true;
                Destroy(restart, 2f);
            }
        }

		GameObject plyer = GameObject.Find ("Player");
		pc = plyer.GetComponent<PlayerController> ();
		rg = plyer.GetComponent<Rigidbody2D> ();



	}

    public void RestaVida()
    {
        if(vida > 1)
        {
            vida--;
            PlayerPrefs.SetInt("life", vida);
            SceneManager.LoadScene("Level_1");

        }
       
        else if (vida == 1)
        {

            PlayerPrefs.DeleteKey("life");
            Destroy(life3);
            vida--;
            gameOver.enabled = true;
			anim.SetInteger ("State", -1);
			pc.playable = false;

			//GAME OVER TODO
        }
    }
        
	private void quitLife(){
		vida--;
		anim.SetInteger ("State", -1);
		pc.playable = false;

		//wait
		//			plyer.position = respawnPos;
		//GOTO SCENE1
	}
    
}
