Basically, I'm trying to make it so that this code updates my GUI to keep track of how much health the player and enemy has. Only problem is that it won't update the GUI, it just stays at 2. The print quotes output the correct health in the console, but not in the GUI. I've only attached this script to my CannonBall and my GUI Text file. Any help would be much appreciated.
var hpPlayer : int = 2;
var hpEnemy : int = 2;
var playerDead : boolean = false;
var enemyDead : boolean = false;
var x = 1;
function OnTriggerEnter(hit : Collider)
{
if (collider.gameObject.tag == "CannonBall")
{
Destroy(collider.gameObject);
}
}
function OnCollisionEnter(collision : Collision){
if(collision.gameObject.tag == "Player"){
hpPlayer--;
print("hit player " + hpPlayer);
if (hpPlayer<=0) playerDead = true;
}
if(collision.gameObject.tag == "Enemy"){
hpEnemy--;
print("hit enemy " + hpEnemy);
if (hpEnemy<=0) enemyDead = true;
}
}
function OnGUI () {
hpP = hpEnemy + "";
GUI.Label (Rect (10, 10, 100, 20), "HP Player: " + (hpPlayer).ToString());
GUI.Label (Rect (10, 30, 100, 20), "HP Enemy: "(hpEnemy).ToString());
}