using UnityEngine; using UnityEngine.UI; public class PlayerUIManager : MonoBehaviour { [Header("References")] [Tooltip("Drag the Player (or the GameObject with PlayerStats) here")] public PlayerStats playerStats; [Header("UI Bars (Sliders)")] [Tooltip("Assign if you are using Unity UI Sliders for your bars")] public Slider healthBar; public Slider manaBar; public Slider staminaBar; [Header("UI Bars (Images - Fill Method)")] [Tooltip("Assign if you are using UI Images with Image Type set to 'Filled'")] public Image healthFill; public Image manaFill; public Image staminaFill; [Header("Combat UI")] public BowAimLayerController bowAimLayerController; [Tooltip("A Slider that fills up from 0 to 1 as the bow is drawn.")] public Slider bowDrawBar; private void Start() { if (playerStats == null) { Debug.LogWarning("PlayerUIManager: PlayerStats reference is missing! Please assign it in the Inspector."); } // Initialize Slider max values if they are being used if (healthBar != null) healthBar.maxValue = playerStats.maxHealth; if (manaBar != null) manaBar.maxValue = playerStats.maxMana; if (staminaBar != null) staminaBar.maxValue = playerStats.maxStamina; if (bowDrawBar != null) { bowDrawBar.minValue = 0f; bowDrawBar.maxValue = 1f; bowDrawBar.value = 0f; } } private void Update() { UpdateBars(); UpdateCombatUI(); } private void UpdateBars() { if (playerStats == null) return; // 1. Update Sliders (if assigned) if (healthBar != null) healthBar.value = playerStats.currentHealth; if (manaBar != null) manaBar.value = playerStats.currentMana; if (staminaBar != null) staminaBar.value = playerStats.currentStamina; // 2. Update Image Fills (if assigned) if (healthFill != null) healthFill.fillAmount = playerStats.currentHealth / playerStats.maxHealth; if (manaFill != null) manaFill.fillAmount = playerStats.currentMana / playerStats.maxMana; if (staminaFill != null) staminaFill.fillAmount = playerStats.currentStamina / playerStats.maxStamina; } private void UpdateCombatUI() { if (bowDrawBar != null && bowAimLayerController != null) { float drawPercentage = bowAimLayerController.CurrentDrawPercentage; bowDrawBar.value = drawPercentage; // Optional: Hide the bar completely if we aren't drawing the bow bowDrawBar.gameObject.SetActive(drawPercentage > 0f); } } }