Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UIHealthAlchemy;
- public class BottleStamina : MonoBehaviour
- {
- private MaterialHealhBar guiBar;
- private staminaSystem staminaSys; // Stamina component, used to use and refill Stamina (didn't have a MaxValue)
- private playerStatsSystem statsSys; // For that reason we need to gain access to the another component.
- private playerStatsSystem.statInfo staminaInfo; // Which contain an array and we need to search for what we need from all StatsInfo that the array contains!
- private float currentStamina;
- private float maxStamina; // This is used for UIHealthAlchemy which works between 0 and 1
- private float oldValue = 0;
- // Start is called before the first frame update
- void Start()
- {
- guiBar = GetComponent<MaterialHealhBar>();
- if (!transform.root.GetComponentInChildren<playerStatsSystem>())
- {
- Debug.LogError("*** MISSING PLAYER STATS SYSTEM ON CHARACTER ***");
- return;
- }
- if (!transform.root.GetComponentInChildren<staminaSystem>())
- {
- Debug.LogError("*** MISSING STAMINA SYSTEM ON CHARACTER ***");
- return;
- }
- statsSys = transform.root.GetComponentInChildren<playerStatsSystem>(); // This is the Component that have all stats, it's an array
- staminaSys = transform.root.GetComponentInChildren<staminaSystem>();
- findStamina(); // this is used to find the Stamina Value from the array of StatInfo array inside the PlayerStatsSystem component
- maxStamina = staminaInfo.currentValue;
- currentStamina = staminaSys.staminaAmount;
- oldValue = currentStamina;
- UpdateUI();
- }
- private void FixedUpdate()
- {
- if (oldValue != staminaSys.staminaAmount)
- UpdateUI();
- }
- public void UpdateUI()
- {
- // Debug.Log(currentStamina +"/"+ maxStamina);
- currentStamina = staminaSys.staminaAmount;
- guiBar.Value = currentStamina / maxStamina; // So we have value with a range 0 to 1
- oldValue = currentStamina;
- }
- private void findStamina()
- {
- for (int i = 0; i < statsSys.statInfoList.Count; i++)
- {
- if (statsSys.statInfoList[i].Name == "Stamina")
- staminaInfo = statsSys.statInfoList[i];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement