Advertisement
Guest User

Untitled

a guest
Sep 1st, 2015
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.77 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4.  
  5. public class PlayerStats : MonoBehaviour
  6. {
  7.  
  8.     #region Player Status Variables
  9.     public Slider healthSlider;
  10.     public Slider thirstySlider;
  11.     public Slider hungrySlider;
  12.     public Slider staminaSlider;
  13.  
  14.     public int MaxStatus = 200;
  15.  
  16.     private float timer = 0;
  17.     private int curHealth = 0;
  18.     private int curThirsty = 0;
  19.     private int curHungry = 0;
  20.     private int curStamina = 0;
  21.     #endregion
  22.  
  23.     #region Player Resources Variables
  24.     public int startResourceValue = 5;
  25.  
  26.     public Text waterCounter;
  27.     public Text foodCounter;
  28.     public Text woodCounter;
  29.     public Text stoneCounter;
  30.  
  31.     private int curWater;
  32.     private int curFood;
  33.     private int curWood;
  34.     private int curStone;
  35.     #endregion
  36.  
  37.     #region Deprecated Vars
  38.     private bool ShowHUD = false;
  39.     private int StatsPanelId = 1;
  40.     private Rect StatsPanelRect = new Rect(0, 0, 0, 0);
  41.     #endregion
  42.  
  43.  
  44.  
  45.     void Start()
  46.     {
  47.         Cursor.visible = true;
  48.         #region Define max values
  49.         healthSlider.maxValue = MaxStatus;
  50.         thirstySlider.maxValue = MaxStatus;
  51.         hungrySlider.maxValue = MaxStatus;
  52.         staminaSlider.maxValue = 100;
  53.         #endregion
  54.  
  55.         #region Resources Redefine
  56.         if (curWater <= 0)
  57.             curWater = startResourceValue;
  58.  
  59.         if (curFood <= 0)
  60.             curFood = startResourceValue;
  61.  
  62.         if (curWood < 0)
  63.             curWood = 0;
  64.  
  65.         if (curStone < 0)
  66.             curStone = 0;
  67.         #endregion
  68.  
  69.         #region Status Redefine
  70.         if (curHealth <= 0)
  71.             curHealth = MaxStatus;
  72.  
  73.         if (curThirsty <= 0)
  74.             curThirsty = MaxStatus;
  75.  
  76.         if (curHungry <= 0)
  77.             curHungry = MaxStatus;
  78.  
  79.         if (curStamina <= 0)
  80.             curStamina = 100;
  81.         #endregion
  82.     }
  83.  
  84.    
  85.     void OnEnable () {
  86.         Messenger.AddListener("AddWater", AddWater);
  87.         Messenger.AddListener("AddFood", AddFood);
  88.         Messenger.AddListener("AddWood", AddWood);
  89.         Messenger.AddListener("AddStone", AddStone);
  90.     }
  91.  
  92.     void AddWater() {
  93.         curWater += 1;
  94.     }
  95.  
  96.     void AddFood() {
  97.         curFood += 1;
  98.     }
  99.  
  100.     void AddWood() {
  101.         curWood += 1;
  102.     }
  103.  
  104.     void AddStone() {
  105.         curStone += 1;
  106.     }
  107.  
  108.     void Update () {
  109.         PlayerInputs();
  110.         waterCounter.text = curWater.ToString();
  111.         foodCounter.text = curFood.ToString();
  112.         woodCounter.text = curWood.ToString();
  113.         stoneCounter.text = curStone.ToString();
  114.  
  115.         healthSlider.value = curHealth;
  116.         thirstySlider.value = curThirsty;
  117.         hungrySlider.value = curHungry;
  118.         staminaSlider.value = curStamina;
  119.  
  120.         timer += Time.deltaTime * 1.0f;
  121.  
  122.         if (timer >= 2) {
  123.             if (curThirsty == 0 && curHungry == 00) {
  124.                 if (curHealth <= MaxStatus && curHealth >= 4) {
  125.                     curHealth -= 4;
  126.                 }
  127.             }
  128.  
  129.             if (curThirsty <= MaxStatus && curThirsty >= 2) {
  130.                 curThirsty -= 2;
  131.             }
  132.  
  133.             if (curHungry <= MaxStatus && curHungry >= 1) {
  134.                 curHungry -= 1;
  135.             }
  136.  
  137.             if (curStamina < 90) {
  138.                 curStamina += 10;
  139.             }
  140.  
  141.             timer = 0;
  142.         }
  143.  
  144.     }
  145.  
  146.     void PlayerInputs() {
  147.         if (Input.GetKeyDown(KeyCode.Alpha1) && curWater > 0) {
  148.             curWater -= 1;
  149.             if(curThirsty <= (MaxStatus-10) && curThirsty > 0)
  150.                 curThirsty += 10;
  151.         }
  152.  
  153.         if (Input.GetKeyDown(KeyCode.Alpha2) && curFood > 0) {
  154.             curFood -= 1;
  155.             if (curFood <= (MaxStatus - 10) && curFood > 0)
  156.                 curFood += 10;
  157.         }
  158.     }
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement