47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
using System;
|
|||
|
public class SkillCoolDownUI : MonoBehaviour
|
|||
|
{
|
|||
|
public Image cooldownImage; // <20>϶<EFBFBD>Image<67><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
public Text cooldowntext;//<2F><>ʾ<EFBFBD><CABE>ʱ<EFBFBD><CAB1>ʣ<EFBFBD><CAA3>ʱ<EFBFBD><CAB1>
|
|||
|
public event Action OnCooldownFinished; // <20><>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
|||
|
|
|||
|
private Coroutine countdownCoroutine;
|
|||
|
|
|||
|
public void StartCooldown(float cooldownTime)
|
|||
|
{
|
|||
|
if (countdownCoroutine != null)
|
|||
|
{
|
|||
|
StopCoroutine(countdownCoroutine);
|
|||
|
}
|
|||
|
countdownCoroutine = StartCoroutine(CooldownRoutine(cooldownTime));
|
|||
|
}
|
|||
|
|
|||
|
private IEnumerator CooldownRoutine(float cooldownTime)
|
|||
|
{
|
|||
|
float elapsed = 0f;
|
|||
|
cooldownImage.fillAmount = 1; // <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>
|
|||
|
|
|||
|
while (elapsed < cooldownTime)
|
|||
|
{
|
|||
|
elapsed += Time.deltaTime;
|
|||
|
cooldownImage.fillAmount = 1 - (elapsed / cooldownTime);
|
|||
|
cooldowntext.text =((1 - (elapsed / cooldownTime))*10).ToString("F1");
|
|||
|
yield return null;
|
|||
|
}
|
|||
|
|
|||
|
HandleCooldownFinished();
|
|||
|
}
|
|||
|
|
|||
|
private void HandleCooldownFinished()
|
|||
|
{
|
|||
|
cooldownImage.fillAmount = 0; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ0
|
|||
|
OnCooldownFinished?.Invoke(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
|||
|
|
|||
|
Destroy(gameObject);
|
|||
|
}
|
|||
|
}
|