var health : playerhealth = gameObject.GetComponent(playerhealth);
var initialGreenLength: float;
var greenBar: GameObject;
var helth: int = health.HP;
var maxHealth: float=100;
function Awake(){
helth=maxHealth;
initialGreenLength=greenBar.transform.localScale.x;
}
function Update(){
greenBar.transform.localScale.x=initialGreenLength*(helth/maxHealth);
}
The
var health : playerhealth = gameObject.GetComponent(playerhealth);
section of the script references another scripts variable of player HP, but it doesn’t seem to be working. This is the other script
var HP : int = 5;
var body = gameObject;
function Update () {
if(HP < 1) {
var instance : GameObject = Instantiate(body, transform.position, transform.rotation);
DestroyObject (gameObject);
}
}
I figured out how to fix it, I deleted the HP bar script, made a GUIText, and changed the player health script to look like this,
var gui : GUIText = gameObject.GetComponent(GUIText);
var HP : int = 5;
var body = gameObject;
function Update () {
gui.text = "Health: "+HP;
if(HP < 1) {
var instance : GameObject = Instantiate(body, transform.position, transform.rotation);
DestroyObject (gameObject);
}
}