Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class PlayerHP : MonoBehaviour {
- public int curHP = 150;
- public int maxHP = 150;
- private float HPBarL;
- void Start () {
- HPBarL = 150;
- }
- void Update () {
- AddJustCurHP(0);
- }
- void OnGUI(){
- GUI.Box(new Rect(60, 25, HPBarL, 20), curHP + "/" + maxHP);
- }
- public void AddJustCurHP(int adj){
- curHP += adj;
- if(curHP < 0)
- curHP = 0;
- if(curHP > maxHP)
- curHP = maxHP;
- if(maxHP < 1)
- maxHP = 1;
- if(curHP < maxHP)
- curHP++;
- HPBarL = (150) * (curHP / (float)maxHP);
- if(HPBarL > 150)
- HPBarL = 150;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment