Unity/유니티 기본
[4.22] UI Animation
ljw4104
2021. 4. 22. 13:20
- 녹화버튼으로 애니메이션 녹화 시작
- 특정 프레임에 특정 값을 Key로 넣으면 그 값으로 애니메이션이 재생됨.
Main 프레임먼저 실행한 후에 다른 오브젝트의 애니메이션을 실행하고 싶으면 다른 오브젝트들을 SetActive(false)한 후에 Main 프레임의 애니메이션이 끝난 후, SetActive(true) 한 후 Play한다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class test : MonoBehaviour
{
public Button btn;
public Animator animator;
public Animator[] animStarts;
public Animator decoAnim;
public Animator crownAnim;
public Text score;
private int tmp = 800000;
// Start is called before the first frame update
void Start()
{
this.animator.speed = 0;
for (int i = 0; i < this.animStarts.Length; i++)
{
this.animStarts[i].speed = 0;
this.animStarts[i].gameObject.SetActive(false);
}
this.decoAnim.gameObject.SetActive(false);
this.decoAnim.speed = 0;
this.crownAnim.gameObject.SetActive(false);
this.crownAnim.speed = 0;
this.btn.onClick.AddListener(() =>
{
this.animator.speed = 0.6f;
StartCoroutine(anim(0.467f, () =>
{
this.decoAnim.gameObject.SetActive(true);
this.decoAnim.Play("deco_anim");
this.decoAnim.speed = 0.7f;
this.crownAnim.gameObject.SetActive(true);
this.crownAnim.Play("crown_anim");
this.crownAnim.speed = 1f;
for (int i = 0; i < 2; i++)
{
this.animStarts[i].gameObject.SetActive(true);
this.animStarts[i].Play("UIPop_Star");
this.animStarts[i].speed = 1f;
}
StartCoroutine(AddNum());
}));
});
}
// Update is called once per frame
void Update()
{
}
private IEnumerator anim(float t, System.Action onComplete)
{
yield return new WaitForSeconds(1f);
onComplete();
}
private IEnumerator AddNum()
{
float tmpScore = 0;
float offset = 800000 / 1f;
while (tmpScore < tmp)
{
tmpScore += offset * Time.deltaTime;
score.text = ((int)tmpScore).ToString();
yield return null;
}
tmpScore = 800000;
score.text = ((int)tmpScore).ToString();
}
}