fix: 아이콘이 정상적으로 출력되지 않는 오류 수정
This commit is contained in:
49
Gameton-06/Assets/Gameton/Scripts/Skill/PotionButtonItem.cs
Normal file
49
Gameton-06/Assets/Gameton/Scripts/Skill/PotionButtonItem.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
public class PotionButtonItem : 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 으로 감소
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user