Hi guys I’m trying to use a lifebar texture as getting smaller instead of just displaying the current life as a number. I’ve been using life as a public float, I can adjust it in the inspector for test runs, it’s worked just fine, I’ve been displaying it as just GUI text in the corner of the screen. I googled a few things looking for help on this and i’ll keep trying different things, may even figure it out before anyone posts here. But if you happen to take a quick look at this and can tell me what I’m doing wrong I’d appreciate it. Heres the script:
Also, in case your wondering, I use other scripts to access the Life float in this script to add damage.
using UnityEngine;
using System.Collections;
public class LifeScript : MonoBehaviour {
public GUITexture healthbar;
public RobotControllerPC RobotControllerPC; //script where my player controller is
public float life = 100f;
private float widthbar;
void Start () {
widthbar = healthbar.pixelInset.width;
}
void Update () {
widthbar = widthbar * life / 100;
if (life <=0f) {
RobotControllerPC.dead = true;
}
}
void OnGUI () { // just keeping this here until the lifebar is figured out
guiText.text = " " + life;
}
}