From ef88576fbf80fcd7b8406f373c6584205108522f Mon Sep 17 00:00:00 2001 From: "aube.lee" Date: Sun, 2 Mar 2025 15:52:17 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B2=8C=EC=9E=84=20=EB=82=B4=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=ED=8F=AC=EC=85=98=20=EC=82=AC=EC=9A=A9=20=EC=A1=B0?= =?UTF-8?q?=EA=B1=B4=20=EB=B0=8F=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scripts/Character/CharacterBase.cs | 22 ++++++-- .../Assets/Gameton/Scripts/UI/ControllerUI.cs | 53 ++++++++++++++----- 2 files changed, 59 insertions(+), 16 deletions(-) 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()