public int Plives; //the lives of player
public GameObject Heart2; //all the prefabs
public GameObject Heart3;
public GameObject Heart1;
public Transform Hr1; //respawnpoint of the lives
public Transform Hr2;
public Camera cam; //the camera
private void Update() //if this has been already run i doesn't work again.
{
if(Plives == 2)
{
Destroy(Heart1);
}
if(Plives == 1) // same for this one
{
Destroy(Heart2);
}
if (Plives == 0) //This one works because it doesn't need to be called twice.
{
Destroy(Heart3);
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 0);
}
if (Plives < 0) //This was created to patch a bug so the lives wont go in negative numbers.
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 0);
}
}
public void Setlive1()
{
if(Plives == 2) //This is the script to make new harts and then parent them to tehe camera.
{
var Lives1 = Instantiate(Heart3, Hr1.position, Quaternion.identity);
Lives1.transform.parent = cam.transform;
Plives += 1;
}
if(Plives == 1)
{
var Lives2 = Instantiate(Heart3, Hr2.position, Quaternion.identity);
Lives2.transform.parent = cam.transform;
Plives += 1;
}
}