I have a script here for a player health system, i am struggling to figure out how to make it that if the player is touched by “enemy” they loose one health.
Thanks
using UnityEngine;
using System.Collections;
public class HealthSystem : MonoBehaviour
{
public int maxHealth = 3;
public int currHealth = 3;
public float healthBarLength;
void Start ()
{
healthBarLength = Screen.width / 2;
}
void Update ()
{
AddjustCurrentHealth(0);
}
void OnGUI()
{
GUI.Box(new Rect(10, 10, healthBarLength, 20), currHealth + "/" + maxHealth);
}
public void AddjustCurrentHealth(int adj)
{
currHealth += adj;
if(currHealth > maxHealth)
currHealth = maxHealth;
if(currHealth < 0)
currHealth = 0;
if(maxHealth < 1)
maxHealth = 1;
healthBarLength = (Screen.width / 2) * (currHealth / (float)maxHealth);
}
}