Okay so i have hunger and thirst that deplete my health when they reach 0 but my player doesn’t die when his health reaches 0, how do i do this?
my health script is in C#(i think i made it look like code):
using UnityEngine;
using System.Collections;
public class PlayerHealth : MonoBehaviour {
public float maxHealth = 100f;
public float curHealth = 100f;
public float healthBarLength;
private Thirst thirst;
private Hunger hunger;
// Use this for initialization
void Start () {
healthBarLength = Screen.width / 2;
thirst = GetComponent(typeof(Thirst)) as Thirst;
hunger = GetComponent(typeof(Hunger)) as Hunger;
}
// Update is called once per frame
void Update () {
AddjustCurrentHealth(0);
if (thirst.thirstLevel <= 0 || hunger.hungerLevel <= 0) {
//variable declaring delay of however many seconds
//int delay = 10;
//delay-= 1;
//if (delay == 0){
//if(delay = 0) execute following line
curHealth -= 0.01f;
//}
}
}
void OnGUI() {
GUI.Box(new Rect (10, 10, healthBarLength, 20), curHealth + “/” + maxHealth);
}
public void AddjustCurrentHealth(int adj){
curHealth += adj;
if(curHealth < 0)
curHealth = 0;
if(curHealth > maxHealth)
curHealth = maxHealth;
if(maxHealth < 1)
maxHealth = 1;
healthBarLength = (Screen.width / 2) * (curHealth / (float)maxHealth);
}
}