This is my first project with Unity and I’m attempting to get a very basic Health bar going.
It draws, and Redraws when the variable changes, although it does not delete the previous rectangle when it draws the new oner. Leaving it at 100/100 health, but when you lose 50, it will say 50/50 ----- 100/100 father to the right.
I have the health bar shrinking with the ammount of health you have, so the text moves.
If you don’t move the text then it just over-laps eachother. Help?
using UnityEngine;
using System.Collections;
public class PlayerHealth : MonoBehaviour {
public int maxHealth = 100;
public int currentHealth = 100;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI() {
GUI.Box(new Rect(10, 10, Screen.width / 2 /(maxHealth / currentHealth), 20), currentHealth + "/" + maxHealth);
}
}