unity图形圆形展开
脚本如下:
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); } }
挂到image上,调用begin方法即可。