_xiaofang/xiaofang/Assets/Script/UI/ZZZZZZ/Progress.cs

35 lines
905 B
C#
Raw Normal View History

2024-12-25 12:02:42 +08:00
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()
{
2024-12-26 18:03:45 +08:00
//StartCoroutine(FillImage(targetImage, fillDuration));
2024-12-25 12:02:42 +08:00
}
2024-12-26 18:03:45 +08:00
public void Start1()
{
StartCoroutine(FillImage(targetImage, fillDuration));
2024-12-25 12:02:42 +08:00
2024-12-26 18:03:45 +08:00
}
2024-12-25 12:02:42 +08:00
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
}
}