Wolvenspud

EW - globalValues

Nov 5th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4.  
  5. public class globalValues : MonoBehaviour {
  6.  
  7.     public enum TextType { money, hitpoints }
  8.  
  9.     public static int moneys = 0;
  10.     public static int theHp = 100;
  11.  
  12.     public Text moneyText;
  13.     public Text hpText;
  14.  
  15.     public static Text _moneyText;
  16.     public static Text _hpText;
  17.  
  18.     private void Start()
  19.     {
  20.         _moneyText = moneyText;
  21.         _hpText = hpText;
  22.         SetText(TextType.money, _moneyText, theHp);
  23.         SetText(TextType.hitpoints, _hpText, moneys);
  24.     }
  25.  
  26.     public static void alterMoney(int addval)
  27.     {
  28.         moneys += addval;
  29.         SetText(TextType.hitpoints, _moneyText, moneys);
  30.     }
  31.  
  32.     public static void alterHp(int damage)
  33.     {
  34.         theHp -= damage;
  35.         SetText(TextType.money, _hpText, theHp);
  36.         if (theHp < 0)
  37.         {
  38.             //endgame
  39.         }
  40.     }
  41.  
  42.     public static void SetText(TextType type, Text text, int value)
  43.     {
  44.         switch (type)
  45.         {
  46.             case TextType.money:
  47.                 text.text = "Money: " +  value.ToString();
  48.                 break;
  49.             case TextType.hitpoints:
  50.                 text.text = "HP: " + value.ToString();
  51.                 break;
  52.             default:
  53.                 break;
  54.         }
  55.     }
  56. }
Add Comment
Please, Sign In to add comment