Unity graphics circular expansion

The script is as follows:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class CircleExpandImage : MonoBehaviour {
    public float timeSeconds = 5f;
    public float timeInterval = 0.05f;

    private Image image;
    private float duration;

    void Start()
    {
        gameObject.SetActive(false);
        image = GetComponent<Image>();
        image.type = Image.Type.Filled;
        image.fillAmount = 0f;
        image.fillOrigin = (int)Image.Origin90.TopRight;
        duration = 0;
    }

    public void begin()
    {
        gameObject.SetActive(true);
        StartCoroutine(DrawCircleImage());
    }

    IEnumerator DrawCircleImage()
    {
        Debug.Log(System.DateTime.Now);
        yield return new WaitForSeconds(timeInterval);
        while (duration < 1f)
        {
            duration += 1f / ((timeSeconds - 0.1f) / timeInterval) * 2;
            image.fillAmount = duration;
            yield return new WaitForSeconds(timeInterval);
        }
        Debug.Log(System.DateTime.Now);
    }
}

Just hang on the image and call the begin method.

Guess you like

Origin blog.csdn.net/TiktokLiveTool/article/details/130572081