Guest User

PlayerHP

a guest
May 26th, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.62 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class PlayerHP : MonoBehaviour {
  5.     public int curHP = 150;
  6.     public int maxHP = 150;
  7.    
  8.     private float HPBarL;
  9.  
  10.     void Start () {
  11.         HPBarL = 150;
  12.     }
  13.    
  14.     void Update () {
  15.         AddJustCurHP(0);
  16.     }
  17.    
  18.     void OnGUI(){
  19.         GUI.Box(new Rect(60, 25, HPBarL, 20), curHP + "/" + maxHP);
  20.     }
  21.    
  22.     public void AddJustCurHP(int adj){
  23.         curHP += adj;
  24.         if(curHP < 0)
  25.             curHP = 0;
  26.         if(curHP > maxHP)
  27.             curHP = maxHP;
  28.         if(maxHP < 1)
  29.             maxHP = 1;
  30.         if(curHP < maxHP)
  31.             curHP++;
  32.        
  33.         HPBarL = (150) * (curHP / (float)maxHP);
  34.         if(HPBarL > 150)
  35.             HPBarL = 150;
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment