this is my code I’m trying to make it so when i collide with my enemy i take damage
static var curHp : float = 100.0;
static var maxHp : float = 50.0;
static var curMana : float = 50.0;
static var maxMana : float = 50.0;
var HpBarTexture : Texture2D;
var ManaBarTexture : Texture2D;
var hpBarLength : float;
var percentOfHp : float;
var manaBarLength : float;
var percentOfMana :float;
var damage : int = 20;
function OnGUI () {
if (curHp > 0) {
GUI.DrawTexture(Rect((Screen.width/2) - 500, 10, hpBarLength, 10), HpBarTexture);
}
if (curMana > 0) {
GUI.DrawTexture(Rect((Screen.width/2) - 500, 20, manaBarLength, 10), ManaBarTexture);
}
}
function Update () {
percentOfHP = curHp/maxHp;
hpBarLength = percentOfHP*100;
percentOfMana = curMana/maxMana;
manaBarLength = percentOfMana*100;
if(Input.GetKeyDown("h")) {
curHp -= 10.0;
}
if(Input.GetKeyDown("m")) {
curMana -= 10.0;
if(collision.collider.tag == "Enemy")
curHp = curHp - damage;
}
}
please help