0% found this document useful (0 votes)
5 views

Script

Uploaded by

jlegno95
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Script

Uploaded by

jlegno95
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

using System.

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

public class Health_and_Damage : MonoBehaviour


{
public int vida;
private GameObject[] corazonesVida;

public bool invencible = false;


public float tiempoInvencible = 1f;
public float tiempoFrenado = 0.2f;

[SerializeField]
private GuardarEscena _guardarEscena;

private void Start()


{
vida = 3;
corazonesVida[0] = GameObject.Find("VidaUnGolpe");
corazonesVida[1] = GameObject.Find("VidaDosGolpes");
corazonesVida[2] = GameObject.Find("Vidas");
_guardarEscena =
GameObject.Find("ControladorDeOpciones").GetComponent<GuardarEscena>();
}
public void RestarVida(int cantidad)
{
if (!invencible && vida == 3)
{
corazonesVida[0].SetActive(true);
corazonesVida[1].SetActive(true);
corazonesVida[2].SetActive(true);

StartCoroutine(Invulnerabilidad());
StartCoroutine(FrenarVelocidad());

}
else if (!invencible && vida == 2)
{
corazonesVida[0].SetActive(true);
corazonesVida[1].SetActive(true);
corazonesVida[2].SetActive(false);

StartCoroutine(Invulnerabilidad());
StartCoroutine(FrenarVelocidad());

}
else if (!invencible && vida == 1)
{
corazonesVida[0].SetActive(true);
corazonesVida[1].SetActive(false);
corazonesVida[2].SetActive(false);

StartCoroutine(Invulnerabilidad());
StartCoroutine(FrenarVelocidad());

}
else if (vida == 0)
{
// guardar esta variable en un objeto que sea comun entre escenas
//SceneManagment.GetActiveScene = new int(GuardarEscena);
//GameObject.find("ControladorDeOpciones");

GameOver();
}
}

void GameOver()
{

_guardarEscena.escenaanterior = SceneManager.GetActiveScene().buildIndex;

SceneManager.LoadScene(4);
}

IEnumerator Invulnerabilidad()
{
invencible = true;
yield return new WaitForSeconds(tiempoInvencible);
invencible = false;
}

IEnumerator FrenarVelocidad()
{
var velocidadActual = GetComponent<Player>().playerSpeed;
GetComponent<Player>().playerSpeed = 0;
yield return new WaitForSeconds(tiempoFrenado);
GetComponent<Player>().playerSpeed = velocidadActual;
}
}

You might also like