Unity3D/Unity & C#
Unity & C# ~ UI Image Fillamount 부드럽게 움직이게 하는 법
캬캬백곰
2022. 7. 4. 16:14
728x90
using UnityEngine.UI;
Image circleProgress;
private const float loopTimeValue = 1.0f; //그리는데 걸리는 시간
public AnimationCurve loopAnimCurve; //그리는 속도를 조정해줄 애니메이션 커브
private float targetValue = 0.0f;
private float currentValue = 0.0f;
void Awake
{
targetValue = 목표값 입력;
currentValue = 0; //현재값 초기화
circleProgress.fillAmount = 0.0f; //progress fillamount 초기화
StartCoroutine(MoveProgressCoroutine());
}
IEnumerator MoveProgressCoroutine()
{
var targetFillAmount = currentValue / targetValue;
var currentFillAmountValue = circleProgress.fillAmount;
var loopTime = 0.0f;
while (loopTime < loopTimeValue)
{
loopTime += (Time.fixedDeltaTime * 0.1f);
circleProgress.fillAmount = Mathf.Lerp(currentFillAmountValue, targetFillAmount, loopAnimCurve.Evaluate(loopTime));
yield return null;
}
}
728x90
반응형