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