diff --git a/Gameton-06/Assets/Gameton/Scripts/Character/CharacterBase.cs b/Gameton-06/Assets/Gameton/Scripts/Character/CharacterBase.cs index deb77509..5200199d 100644 --- a/Gameton-06/Assets/Gameton/Scripts/Character/CharacterBase.cs +++ b/Gameton-06/Assets/Gameton/Scripts/Character/CharacterBase.cs @@ -40,10 +40,10 @@ namespace TON [SerializeField] private float mpRecoveryRate = 1f; // MP 회복량 [SerializeField] private float mpRecoveryInterval = 3f; // 회복 간격(초) [SerializeField] private bool isRecovering = false; - + public AudioClip _attackSound; public AudioClip _deathSound; - + public void Start() { animator = GetComponent(); @@ -174,7 +174,7 @@ namespace TON isAttack = true; // 공격 애니메이션 적용 animator.Play("Default Attack"); - + SoundManager.instance.SFXPlay("Attack", _attackSound); // 공격 범위 Collider 활성화 @@ -210,8 +210,20 @@ namespace TON isRecovering = false; } - public void UsePotion(string type) + public void UsePotion(string type, System.Action callback) { + + if (type.Equals("HP") && currentHP == maxHP) + { + callback?.Invoke(false); + return; + } + if (type.Equals("MP") && currentSP == maxSP) + { + callback?.Invoke(false); + return; + } + switch (type) { case "HP": @@ -229,6 +241,8 @@ namespace TON } break; } + + callback?.Invoke(true); } public void SkillAttack(string skillId) diff --git a/Gameton-06/Assets/Gameton/Scripts/UI/ControllerUI.cs b/Gameton-06/Assets/Gameton/Scripts/UI/ControllerUI.cs index d32d9fc7..5b9b3b4a 100644 --- a/Gameton-06/Assets/Gameton/Scripts/UI/ControllerUI.cs +++ b/Gameton-06/Assets/Gameton/Scripts/UI/ControllerUI.cs @@ -26,17 +26,22 @@ namespace TON [SerializeField] private TextMeshProUGUI hpPotionCount; [SerializeField] private TextMeshProUGUI mpPotionCount; + private int potionLimit = 5; // 게임에서 사용할 수 있는 포션 수 제한 + private int hpPotion = 0; + private int mpPotion = 0; + public List itemButtons = new List(); private void OnEnable() { skillButtonPrefab.gameObject.SetActive(false); Initalize(); + InitalizeItemData(); } private void FixedUpdate() { - InitalizeItemData(); + SetPotionText(); } public void Initalize() @@ -76,30 +81,54 @@ namespace TON { userItem = PlayerDataManager.Singleton.userItem; - hpPotionCount.text = $"{userItem.hpPotion}"; - mpPotionCount.text = $"{userItem.mpPotion}"; + // 게임 진입 시 포션 초기 수량 세팅팅 + hpPotion = userItem.hpPotion >= potionLimit ? potionLimit : userItem.hpPotion; + mpPotion = userItem.mpPotion >= potionLimit ? potionLimit : userItem.mpPotion; + + SetPotionText(); } + // 현재 인게임 내에서 사용중인 포션의 숫자 업데이트 + private void SetPotionText() + { + hpPotionCount.text = $"{hpPotion}"; + mpPotionCount.text = $"{mpPotion}"; + } + + public void OnClickHpPotionButton() { - if (userItem.hpPotion <= 0) + if (hpPotion <= 0) return; - PlayerDataManager.Singleton.UsePotion("HP"); - - itemButtons[0].SetCurrentCoolDown(); - linkedCharactor.UsePotion("HP"); + // 현재 캐릭터가 포션을 사용할 수 있는 상태일때만 포션 수 감소 + linkedCharactor.UsePotion("HP", isSuccess => + { + if (isSuccess) + { + hpPotion--; + PlayerDataManager.Singleton.UsePotion("HP"); + itemButtons[0].SetCurrentCoolDown(); + } + }); } public void OnClickMpPotionButton() { - if (userItem.mpPotion <= 0) + if (mpPotion <= 0) return; - PlayerDataManager.Singleton.UsePotion("MP"); + // 현재 캐릭터가 포션을 사용할 수 있는 상태일때만 포션 수 감소 + linkedCharactor.UsePotion("MP", isSuccess => + { + if (isSuccess) + { + mpPotion--; + PlayerDataManager.Singleton.UsePotion("MP"); + itemButtons[1].SetCurrentCoolDown(); + } + }); - itemButtons[1].SetCurrentCoolDown(); - linkedCharactor.UsePotion("MP"); } public void OnClickJumpButton()