feat: 플레이 중 포션 사용 로직 적용
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
@@ -20,12 +21,24 @@ namespace TON
|
||||
public ControllerUI_SkillButton skillButtonPrefab;
|
||||
private List<ControllerUI_SkillButton> createdSkillButtons = new List<ControllerUI_SkillButton>();
|
||||
|
||||
public UserItemData userItem { get; private set; } = new UserItemData();
|
||||
// 보유 포션 수량
|
||||
[SerializeField] private TextMeshProUGUI hpPotionCount;
|
||||
[SerializeField] private TextMeshProUGUI mpPotionCount;
|
||||
|
||||
public List<ControllerUI_ItemButton> itemButtons = new List<ControllerUI_ItemButton>();
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
skillButtonPrefab.gameObject.SetActive(false);
|
||||
Initalize();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
InitalizeItemData();
|
||||
}
|
||||
|
||||
public void Initalize()
|
||||
{
|
||||
// 이미 기존에 UI가 생성되어 있다면 삭제
|
||||
@@ -59,6 +72,36 @@ namespace TON
|
||||
}
|
||||
}
|
||||
|
||||
private void InitalizeItemData()
|
||||
{
|
||||
userItem = PlayerDataManager.Singleton.userItem;
|
||||
|
||||
hpPotionCount.text = $"{userItem.hpPotion}";
|
||||
mpPotionCount.text = $"{userItem.mpPotion}";
|
||||
}
|
||||
|
||||
public void OnClickHpPotionButton()
|
||||
{
|
||||
if (userItem.hpPotion <= 0)
|
||||
return;
|
||||
|
||||
PlayerDataManager.Singleton.UsePotion("HP");
|
||||
|
||||
itemButtons[0].SetCurrentCoolDown();
|
||||
linkedCharactor.UsePotion("HP");
|
||||
}
|
||||
|
||||
public void OnClickMpPotionButton()
|
||||
{
|
||||
if (userItem.mpPotion <= 0)
|
||||
return;
|
||||
|
||||
PlayerDataManager.Singleton.UsePotion("MP");
|
||||
|
||||
itemButtons[1].SetCurrentCoolDown();
|
||||
linkedCharactor.UsePotion("MP");
|
||||
}
|
||||
|
||||
public void OnClickJumpButton()
|
||||
{
|
||||
linkedCharactor.Jump();
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
public class ControllerUI_ItemButton : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TextMeshProUGUI coolTimeText;
|
||||
[SerializeField] private Image coolTimeDimd;
|
||||
|
||||
private float currentCoolDown = 0f;
|
||||
private float potionCoolDown = 5f;
|
||||
|
||||
public void SetCurrentCoolDown()
|
||||
{
|
||||
currentCoolDown = potionCoolDown; // 쿨타임 시작
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (currentCoolDown == 0f)
|
||||
return;
|
||||
|
||||
UpdateCooldownUI();
|
||||
}
|
||||
|
||||
private void UpdateCooldownUI()
|
||||
{
|
||||
if (coolTimeText == null || coolTimeDimd == null)
|
||||
{
|
||||
return; // UI가 삭제되었으면 업데이트 중단
|
||||
}
|
||||
|
||||
currentCoolDown -= Time.deltaTime;
|
||||
currentCoolDown = Mathf.Max(0, currentCoolDown);
|
||||
|
||||
coolTimeText.gameObject.SetActive(currentCoolDown > 0); // 남은 쿨타임이 있을 때만 표시
|
||||
|
||||
if (coolTimeText.IsActive())
|
||||
{
|
||||
coolTimeText.text = $"{currentCoolDown: 0}s"; // 정수 초단위 표시
|
||||
coolTimeDimd.fillAmount = currentCoolDown / potionCoolDown; // 1 → 0 으로 감소
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e890b5f706c997b4396fb3fc11938954
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user