using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; public class PlayerLevelSystem : MonoBehaviour { [Header("--- 참조 ---")] [SerializeField] private Stats stats; [SerializeField] private PlayerHealth pHealth; [Header("레벨 설정")] public int level = 1; public int currentExp = 0; [SerializeField] private int[] expTable; [Header("UI")] [SerializeField] private Image expFillImage; [SerializeField] private TextMeshProUGUI expText; [SerializeField] private TextMeshProUGUI levelText; public static System.Action OnLevelUp; private int RequiredExp { get { int index = level - 1; if (index >= expTable.Length) return expTable[expTable.Length - 1]; return expTable[index]; } } private void OnEnable() { MonsterClass.OnMonsterKilled += GainExp; UpdateExpUI(); } private void OnDisable() { MonsterClass.OnMonsterKilled -= GainExp; } void GainExp(int amount) { currentExp += amount; while (currentExp >= RequiredExp) { currentExp -= RequiredExp; LevelUp(); } UpdateExpUI(); } void LevelUp() { if (level >= expTable.Length + 1) { currentExp = 0; return; } level++; // ✨ 힘 대신 공격력(+10) 증가 if (stats != null) stats.AddBaseLevelUpStats(1000f, 10f); if (pHealth != null) pHealth.RefreshHealthUI(); StartCoroutine(DelayedCardPopup()); } private IEnumerator DelayedCardPopup() { yield return new WaitForSeconds(1.5f); OnLevelUp?.Invoke(); } void UpdateExpUI() { float fill = (float)currentExp / RequiredExp; if (expFillImage != null) expFillImage.fillAmount = fill; if (expText != null) expText.text = $"{currentExp} / {RequiredExp}"; if (levelText != null) levelText.text = $"Lv. {level}"; } }