Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using UnityEngine.UI;
- public class PlayerStats : MonoBehaviour
- {
- #region Player Status Variables
- public Slider healthSlider;
- public Slider thirstySlider;
- public Slider hungrySlider;
- public Slider staminaSlider;
- public int MaxStatus = 200;
- private float timer = 0;
- private int curHealth = 0;
- private int curThirsty = 0;
- private int curHungry = 0;
- private int curStamina = 0;
- #endregion
- #region Player Resources Variables
- public int startResourceValue = 5;
- public Text waterCounter;
- public Text foodCounter;
- public Text woodCounter;
- public Text stoneCounter;
- private int curWater;
- private int curFood;
- private int curWood;
- private int curStone;
- #endregion
- #region Deprecated Vars
- private bool ShowHUD = false;
- private int StatsPanelId = 1;
- private Rect StatsPanelRect = new Rect(0, 0, 0, 0);
- #endregion
- void Start()
- {
- Cursor.visible = true;
- #region Define max values
- healthSlider.maxValue = MaxStatus;
- thirstySlider.maxValue = MaxStatus;
- hungrySlider.maxValue = MaxStatus;
- staminaSlider.maxValue = 100;
- #endregion
- #region Resources Redefine
- if (curWater <= 0)
- curWater = startResourceValue;
- if (curFood <= 0)
- curFood = startResourceValue;
- if (curWood < 0)
- curWood = 0;
- if (curStone < 0)
- curStone = 0;
- #endregion
- #region Status Redefine
- if (curHealth <= 0)
- curHealth = MaxStatus;
- if (curThirsty <= 0)
- curThirsty = MaxStatus;
- if (curHungry <= 0)
- curHungry = MaxStatus;
- if (curStamina <= 0)
- curStamina = 100;
- #endregion
- }
- void OnEnable () {
- Messenger.AddListener("AddWater", AddWater);
- Messenger.AddListener("AddFood", AddFood);
- Messenger.AddListener("AddWood", AddWood);
- Messenger.AddListener("AddStone", AddStone);
- }
- void AddWater() {
- curWater += 1;
- }
- void AddFood() {
- curFood += 1;
- }
- void AddWood() {
- curWood += 1;
- }
- void AddStone() {
- curStone += 1;
- }
- void Update () {
- PlayerInputs();
- waterCounter.text = curWater.ToString();
- foodCounter.text = curFood.ToString();
- woodCounter.text = curWood.ToString();
- stoneCounter.text = curStone.ToString();
- healthSlider.value = curHealth;
- thirstySlider.value = curThirsty;
- hungrySlider.value = curHungry;
- staminaSlider.value = curStamina;
- timer += Time.deltaTime * 1.0f;
- if (timer >= 2) {
- if (curThirsty == 0 && curHungry == 00) {
- if (curHealth <= MaxStatus && curHealth >= 4) {
- curHealth -= 4;
- }
- }
- if (curThirsty <= MaxStatus && curThirsty >= 2) {
- curThirsty -= 2;
- }
- if (curHungry <= MaxStatus && curHungry >= 1) {
- curHungry -= 1;
- }
- if (curStamina < 90) {
- curStamina += 10;
- }
- timer = 0;
- }
- }
- void PlayerInputs() {
- if (Input.GetKeyDown(KeyCode.Alpha1) && curWater > 0) {
- curWater -= 1;
- if(curThirsty <= (MaxStatus-10) && curThirsty > 0)
- curThirsty += 10;
- }
- if (Input.GetKeyDown(KeyCode.Alpha2) && curFood > 0) {
- curFood -= 1;
- if (curFood <= (MaxStatus - 10) && curFood > 0)
- curFood += 10;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement