본문 바로가기
개발/C#

유니티 C# 윈도우 창 애니메이션 Window Animation 간단 사용법

by SPNK 2022. 6. 20.
반응형
  • 코드 작성 (Dotween 사용)
using UnityEngine;
using System.Collections;
using DG.Tweening;

public class WindowAnimation : MonoBehaviour
{
    float duration = 0.15f;

    Vector3 scaleTo = new Vector3(1f, 1f, 1f);

    void OnEnable()
    {
        transform.localScale = new Vector3(0, 0, 0);
        transform.DOScale(scaleTo, duration);
    }

    void OnDisable()
    {
        transform.localScale = new Vector3(0, 0, 0);
    }
}

 

  • 코드 작성
using UnityEngine;
using System.Collections;

public class WindowAnimation : MonoBehaviour
{
    [Range(0, 0.5f)]
    public float speed = 0.1f;

    float size = 0;

    void OnEnable()
    {
        size = 0;
        transform.localScale = Vector3.zero;

        StopAllCoroutines();
        StartCoroutine(SizeCoroution());
    }

    IEnumerator SizeCoroution()
    {
        if (size < 1)
        {
            size += speed;
        }
        else
        {
            yield break;
        }

        transform.localScale = Vector3.one * size;

        yield return new WaitForSeconds(0.01f);
        StartCoroutine(SizeCoroution());
    }
}
반응형

댓글