- using UnityEngine;
using System.Collections;
public class PlayerHealth : MonoBehaviour {
public int maxHealth = 100;
public int curHealth = 100;
public float healthBarLength;
// Use this for initialization
void Start () {
healthBarLength = Screen.width /2;
}
// Update is called once per frame
void Update () {
AddjustCurrentHealth(0);
}
void OnGUI(){
GUI.Box (new Rect(10,10, healthBarLength, 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;
healthBarLength =(Screen.width /2) * (curHealth / (float)maxHealth);
}
}
I put this code in and the health bar is being shown in the top left hand corner of the screen. I am having trouble at the moment getting it to decrease everytime you go near Alisairs tree's or if you go in the water. It probably needs an if, else statement, Cat when your are next in i'll show you what happens and you might be able to help me get it to work :- )
Yeah the unityanswers this code came from doesnt have any solutions I doubt we are actually going to get this to work
Yeah the unityanswers this code came from doesnt have any solutions I doubt we are actually going to get this to work
No comments:
Post a Comment