Advertisement
kasru

Hp & Mana Bar

Jan 23rd, 2013
10,876
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //****** Donations are greatly appreciated.  ******
  2. //****** You can donate directly to Jesse through paypal at  https://www.paypal.me/JEtzler   ******
  3.  
  4. static var curHp : float = 300.0;
  5. static var maxHp : float = 300.0;
  6. static var curMana : float = 50.0;
  7. static var maxMana : float = 50.0;
  8. var HpBarTexture : Texture2D;
  9. var ManaBarTexture : Texture2D;
  10. var hpBarLength : float;
  11. var percentOfHp : float;
  12. var manaBarLength : float;
  13. var percentOfMana :float;
  14.  
  15.  
  16. function OnGUI () {
  17.  
  18.     if (curHp > 0) {
  19.             GUI.DrawTexture(Rect((Screen.width/2) - 100, 10, hpBarLength, 10), HpBarTexture);
  20.         }
  21.         if (curMana > 0) {
  22.             GUI.DrawTexture(Rect((Screen.width/2) - 100, 20, manaBarLength, 10), ManaBarTexture);
  23.         }
  24. }
  25.  
  26. function Update () {
  27.  
  28.     percentOfHP = curHp/maxHp;
  29.     hpBarLength = percentOfHP*100;
  30.  
  31.     percentOfMana = curMana/maxMana;
  32.     manaBarLength = percentOfMana*100;
  33.  
  34.     if(Input.GetKeyDown("h")) {
  35.         curHp -= 10.0;
  36.     }
  37.  
  38.     if(Input.GetKeyDown("m")) {
  39.         curMana -= 10.0;
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement