Hello there i made an hp bar in unity 3d with gui.box But after i wrote the code and fixed all errors, i cant get it to show in the game can anyone please assist me with that.
here is the code :
using UnityEngine;
using System.Collections;
public class PlayerHealth : MonoBehaviour {
public int maxHealth = 100;
public int curHealth = 100;
public float healthBarLenght;
// Use this for initialization
void Start () {
healthBarLenght = Screen.width / 2;
}
// Update is called once per frame
void Update () {
AddJustCurrentHealth (0);
}
void onGUI() {
GUI.Box(new Rect(10, 10, healthBarLenght, 20), curHealth + “/” + maxHealth);
}
public void AddJustCurrentHealth(int adj){
curHealth += adj;
if (curHealth < 0)
curHealth = 0;
if (curHealth > maxHealth)
curHealth = maxHealth;
if (maxHealth < 1)
maxHealth = 1;
healthBarLenght = (Screen.width/2) * (curHealth / (float)maxHealth);
}
}
thx for all the help i can get here!