How would i make my hunger and thirst decrease my health?

Im relatively new to this and i wanted to make a basic health thirst system, i dont know how to make the health go down when thirst or hunger reach 0, any ideas what i should do? i postesd the scripts if that helps

health script C#:

using UnityEngine;
using System.Collections;

public class PlayerHealth : MonoBehaviour {
public int maxHealth = 100;
public int curHealth = 100;

public float healthBarLength;
// Use this for initialization
void Start () {
healthBarLength = Screen.width / 2;
}

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

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);
}
}

This is the hunger and thirst scripts:
hunger js.:

var hunger = 100.0; //or any other value;
var hungerSpeed = .1;

function Update ()
{
hunger -= Time.deltaTime * hungerSpeed;
}

Thirst .js:

var Thirst = 100.0; //or any other value;
var ThirstSpeed = .02;

function Update ()
{
Thirst -= Time.deltaTime * ThirstSpeed;
}

[1545-basicscripts.zip|1545]Hello everett24,

I’d add in the following code in the PlayerHealth.cs file:


//Add these two declarations to the top outside of all functions:
private Thirst thirst;
private Hunger hunger;

//Add these two declarations to the start():
thirst = GetComponent(typeof(Thirst)) as Thirst;
hunger = GetComponent(typeof(Hunger)) as Hunger;

//Add this to the Update():
if (thirst.Thirst <= 0 || hunger.Hunger <= 0)
{
curHealth = curHealth - 10; // change the 10 to whatever damage you want
}

I don’t really use .js files in Unity, so you might need to declare Thirst and Hunger in their respective files as public in order to allow outside classes to use them.