started building NPC combat
This commit is contained in:
55
Assets/Scripts/PlayerUIManager.cs
Normal file
55
Assets/Scripts/PlayerUIManager.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
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;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (playerStats == null)
|
||||
{
|
||||
Debug.LogWarning("PlayerUIManager: PlayerStats reference is missing! Please assign it in the Inspector.");
|
||||
return;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (playerStats == null) return;
|
||||
|
||||
UpdateBars();
|
||||
}
|
||||
|
||||
private void UpdateBars()
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user