[Memo-Unity] 29. StateMachine
์นดํ ๊ณ ๋ฆฌ: MeMo Unity
ํ๊ทธ: C#, MeMo Unity
StateMachine
OnStateEnter
OnStateExit
OnStateUpdate
StateMachine
StateMachine
StateMachine
StateMachine StateMachineBehaviour
์ ๋ํฐ์์๋ StateMachine์ ์ง์ ๊ตฌํํ ์๋ ์๊ณ , ์ ๋ํฐ์์ ์ ๋๋ฉ์ดํฐ์ ํ์ฅํ์ฌ ์ฌ์ฉํ ์ ์๋ StateMachineBehaviour๋ฅผ ์ ๊ณตํฉ๋๋ค.
StateMachine.cs
using UnityEngine;
public class AttackBehaviour : StateMachineBehaviour
{
public GameObject particle;
public float radius;
public float power;
protected GameObject clone;
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
Debug.Log("OnStateEnter ");
clone = Instantiate(particle, animator.rootPosition, Quaternion.identity) as GameObject;
Rigidbody rb = clone.GetComponent<Rigidbody>();
rb.AddExplosionForce(power, animator.rootPosition, radius, 3.0f);
}
override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
Debug.Log("OnStateExit ");
Destroy(clone);
}
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
Debug.Log("On Attack Update ");
}
override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
Debug.Log("On Attack Move ");
}
override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
Debug.Log("On Attack IK ");
}
}
- OnStateEnter ์ ๋๋ฉ์ด์ ์คํ ์
- OnStateExit ์ ๋๋ฉ์ด์ ์ข ๋ฃ ์
- OnStateUpdate ๋งค ํ๋ ์๋ง๋ค ์คํ
- OnAnimatorMove: ์ ๋ฐ์ดํธ ํ๋ ์๋ง๋ค ๋ฃจํธ ๋ชจ์ ์ ์์ ํ ์ ์๋๋ก ๊ฐ Animator ์ปดํฌ๋ํธ์ ๋ํด ํ ๋ฒ ํธ์ถ๋ฉ๋๋ค.
- OnAnimatorIK: ์ ๋๋ฉ์ด์ IK๋ฅผ ์ค์ ํฉ๋๋ค. IK pass๊ฐ ํ์ฑํ๋ ๊ฐ ์ ๋๋ฉ์ดํฐ ์ปจํธ๋กค๋ฌ ๋ ์ด์ด์ ๋ํด ํ ๋ฒ ํธ์ถ๋ฉ๋๋ค.
์ก๋ด
์ ๋๋ฉ์ด์ ์ ์คํฌ๋ฆฝํธ ์ฌ์ฉ StateMachineBehaviour
[Unity] StateMachine
TOP
๋๊ธ๋จ๊ธฐ๊ธฐ