I’m pretty sure that you have to use a string instead of a float, so you can type in the OnGUI function, var stringHealth : string = health.ToString();
Then replace health with stringHealth
So it’d be
var health : float = 100f;
var damagePerShot : float = 50f;
function OnTriggerEnter (other : Collider) {
if (other.gameObject.tag == "Bullet") {
health -= damagePerShot;
Destroy(other.gameObject);
}
}
function Update() {
if (health <= 0) {
health = 100f;
transform.position.x = 15;
transform.position.y = 2.5;
transform.position.z = 28.5;
transform.rotation.x = 0;
transform.rotation.y = 180;
transform.rotation.z = 0;
}
}
function OnGUI() {
var stringHealth : string = health.ToString();
GUI.Box(new Rect(0,0,100,100), stringHealth);
}