본문 바로가기
programming | development/unity

Unity AnimationCurve 활용

by foooo828 2023. 4. 18.
    public AnimationCurve myCurve;
    public GameObject animationObject;
    public float duration;
	
    void zoomIn()
    {
        StartCoroutine(MyAnimation(animationObject, .2f, .5f, duration));
    }

    void ZoomOut()
    {
        StartCoroutine(MyAnimation(animationObject, .5f, .2f, duration));
    }
public IEnumerator MyAnimation(GameObject animationObject, float A, float B, float duration)
{
    float elapsedTime = 0;
    while (elapsedTime < duration)
    {
        elapsedTime += Time.deltaTime;
        var per = elapsedTime / duration;
        var startValue = A < B ? A : B;
        var process = A < B ? per : 1 - per; // 커브 뒤집는용
        animationObject.transform.localScale = Vector3.one * (startValue + Mathf.Abs(B - A) * myCurve.Evaluate(process));
        yield return new WaitForEndOfFrame();
    }
}

또잉 하는 애니메이션을 그래프를 이용해서 직관적인 조정 가능

'programming | development > unity' 카테고리의 다른 글

삼각함수로 원 그리기  (0) 2022.07.15
Unity + Realsense F200  (0) 2022.06.14
HDRP Raytracing 세팅  (0) 2022.03.14
Unity + OpenCV OpticalFlowPyrLK + Visual Effect Graph  (0) 2022.03.10
Component Inspector 항목들  (0) 2022.02.26

댓글