public float m_TotalTime = 5f;
private float m_changeSpeed = 0;
private Image m_bgImg;
private void Start()
{
m_bgImg = GetComponent<Image>();
m_changeSpeed = 1 / m_TotalTime;
StartCoroutine(ShowCountingDown());
}
float timer = 0f;
IEnumerator ShowCountingDown()
{
while (m_bgImg.fillAmount > 0)
{
m_bgImg.fillAmount -= m_changeSpeed * Time.deltaTime;
yield return new WaitForSeconds(Time.deltaTime);
}
StopCoroutine(ShowCountingDown());
}
此处是5秒内将img的fillAmount变为0,不同需求自行修改