
using JetBrains.Annotations;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
public class SkillBtnController : MonoBehaviour
{
public Button coolbtn;
public Image coolTimeWheel;
public TMP_Text countText;
public Image skillIcon;
public int coolCount; // 총 카운트
void Start()
{
this.coolbtn.onClick.AddListener(() =>
{
Debug.Log("시작");
StartCoroutine(CoCoolTime());
});
}
IEnumerator CoCoolTime()
{
this.skillIcon.color = Color.yellow;
if (coolTimeWheel != null)
{
Debug.Log("<color=red>실행 중</color>");
coolbtn.interactable = false; // 실행 중일 때 버튼 못누르게 막음
// 여기에 깜빡이 스탑코루틴 넣을 수 있을 듯: 휠이 돌아가는 중이면 깜박이 종료
yield return null;
}
coolTimeWheel.fillAmount = 1f; // 쿨타임 이미지 채워지는 총 량 100%
while (true)
{
// 쿨타임 카운트 시작
float cooltime = coolTimeWheel.fillAmount * coolCount;
cooltime -= Time.deltaTime;
coolTimeWheel.fillAmount = cooltime / coolCount; // 1틱 당 채워지는 양
// 카운트 텍스트 출력
int time = Mathf.RoundToInt(cooltime); // 양수만 표시
countText.text = time.ToString(); // 인트를 스트링으로 변환
// 쿨타임이 0 이면
if (cooltime < 0f)
{
countText.text = "";
coolbtn.interactable = true; // 버튼 활성화
break;
}
yield return null;
}
Debug.Log("코루틴 종료");
}
}
특정 위치를 눌러야 실행된다. 버튼 설정 범위는 잘들어가 있다.
뭐가 문제일까...
'게임 UI,UX 프로그래밍' 카테고리의 다른 글
| 체크 박스 (0) | 2024.08.30 |
|---|---|
| 인풋필드 만들기 (0) | 2024.08.29 |
| 슬라이더 버튼 만들기 (0) | 2024.08.29 |
| toggle 스위치 버튼 만들기 (0) | 2024.08.29 |
| 버튼 클릭하기 (0) | 2024.08.29 |