31 lines
804 B
C#
31 lines
804 B
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
|
|||
|
public class Progress : MonoBehaviour
|
|||
|
{
|
|||
|
public Image targetImage; // Ҫ<><D2AA><EFBFBD>Ƶ<EFBFBD>ͼƬ
|
|||
|
public float fillDuration = 1f; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>䣨<EFBFBD>룩
|
|||
|
|
|||
|
void Start()
|
|||
|
{
|
|||
|
StartCoroutine(FillImage(targetImage, fillDuration));
|
|||
|
}
|
|||
|
|
|||
|
private IEnumerator FillImage(Image image, float duration)
|
|||
|
{
|
|||
|
float elapsed = 0f; // <20><>ʱ<EFBFBD><CAB1>
|
|||
|
image.fillAmount = 0f; //ǿ<><C7BF>Ϊ0
|
|||
|
|
|||
|
while (elapsed < duration)
|
|||
|
{
|
|||
|
elapsed += Time.deltaTime; // <20>ۼ<EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
image.fillAmount = Mathf.Clamp01(elapsed / duration); // <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
yield return null; // <20>ȴ<EFBFBD><C8B4><EFBFBD>һ֡
|
|||
|
}
|
|||
|
|
|||
|
image.fillAmount = 1f; // ȷ<><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>Ϊ1
|
|||
|
}
|
|||
|
}
|