Animator 이용법 자습
Unity/Study 2019. 5. 9. 16:19Animator에는 크게 State와 Transition으로 이루어진다.
State는 상태, Transition은 State와 State를 이어주는 전이로서, Transition에 있는 Conditions라는 조건을 통해
다른 State로 Animation을 전환할 수 있게 해준다.
즉, 위의 사진을 예시로 했을 때, Conditions에 isJump라는 Parameter가 조건으로 있으므로, isJump가 참이 되면
fox_idle이라는 state에서 fox_jump라는 state로 변화하게 되는 것이다.
Animator.Play를 이용한 Animation 재생
Animator의 Trigger Parameter를 이용한 Animation 재생
Animator의 Bool Parameter를 이용한 Animation 재생
Float형 Parameter를 이용하여 Animation의 Speed를 조절하기
Inspector 창에서 Multiplier항에 Parameter를 체크하고 지정해주면,
해당 Parameter의 값을 기준으로 해당 항목의 값이 변화한다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class TestAnim : MonoBehaviour { public Animator anim; public Button[] btn; private void Awake() { this.anim = this.gameObject.GetComponentInChildren<Animator>(); } private void Start() { this.ControlAnimation(); } private void ControlAnimation() { this.btn[0].onClick.AddListener(() => { StartCoroutine(this.PlayAnimation("fox_idle")); }); this.btn[1].onClick.AddListener(() => { StartCoroutine(this.PlayAnimation("fox_run")); }); this.btn[2].onClick.AddListener(() => { StartCoroutine(this.PlayAnimation("fox_jump")); }); this.btn[3].onClick.AddListener(() => { StartCoroutine(this.PlayAnimation("fox_hurt")); }); this.btn[4].onClick.AddListener(() => { StartCoroutine(this.PlayAnimation("fox_crouch")); }); this.btn[5].onClick.AddListener(() => { StartCoroutine(this.PlayAnimation("fox_climb")); }); } private IEnumerator PlayAnimation(string animName) { this.anim.Play(animName); yield return new WaitForSeconds(this.anim.GetCurrentAnimatorStateInfo(0).length); yield return new WaitForSeconds(2.0f); this.anim.SetFloat("AnimationSpeed", 2.0f); yield return new WaitForSeconds(2.0f); this.anim.SetFloat("AnimationSpeed", 3.0f); yield return new WaitForSeconds(2.0f); this.anim.SetFloat("AnimationSpeed", 5.0f); } } | cs |
'Unity > Study' 카테고리의 다른 글
testgpgs개인정보 (0) | 2019.06.13 |
---|---|
GitHub (0) | 2019.05.02 |
3D와 랜더링 파이프라인 (0) | 2019.04.19 |