본문 바로가기
개발/C#

유니티 C# UI 이미지 FillAmount 서서히 감소시키기 간단 구현

by SPNK 2023. 9. 14.
반응형
  • 코드 작성
using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class FillAmountChange : MonoBehaviour
{
    public Image image;
    public float duration = 30.0f;

    private void Start()
    {
        StartCoroutine(ChangeFillAmountOverTime());
    }

    private IEnumerator ChangeFillAmountOverTime()
    {
        float currentTime = 0.0f;
        float startFillAmount = 1.0f;
        float endFillAmount = 0.0f;

        while (currentTime < duration)
        {
            float fillAmount = Mathf.Lerp(startFillAmount, endFillAmount, currentTime / duration);
            fillAmount = Mathf.Clamp01(fillAmount);
            
            image.fillAmount = fillAmount;
            currentTime += Time.deltaTime;
            
            yield return null;
        }

        image.fillAmount = endFillAmount;
    }
}
반응형

댓글