Alright, Hello guys.
I am trying to get my health bar to gradually decrease over time.
I have got it so that when you click the mouse the health goes down, but how do I make it go down by itself?
I’d also like to know how to go about a script to attach to a ‘medkit’ type object so that it adds say, 10hp back onto the health bar?
So at the moment I am using a guitexture for the bar.
Below is the code that makes it diminish with the mouseclick.
var maximumHitPoints = 10.0;
var hitPoints = 10.0;
var healthGUI : GUITexture;
var die : AudioClip;
var buttonDown : boolean = false;
//var resetPoints : float = 0.0;
var damage : float = 0.0;
private var healthGUIWidth = 0.0;
function Awake () {
healthGUIWidth = healthGUI.pixelInset.width;
}
function Update() {
if (Input.GetButton("Fire1"))
{
damage = Time.deltaTime;
ApplyDamage();
}
}
function LateUpdate () {
UpdateGUI();
}
function ApplyDamage () {
hitPoints -= damage;
if (hitPoints < 0.0)
Die();
}
function Die () {
if (die)
AudioSource.PlayClipAtPoint(die, transform.position);
}
function UpdateGUI () {
var healthFraction = Mathf.Clamp01(hitPoints / maximumHitPoints);
healthGUI.pixelInset.xMax = healthGUI.pixelInset.xMin + healthGUIWidth * healthFraction;
}