started building NPC combat

This commit is contained in:
2026-09-29 16:11:54 +01:00
parent be2e7a5824
commit 7486c8d310
4952 changed files with 1093899 additions and 745 deletions

View 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;
}
}