[Memo-Unity] 29. StateMachine

์—…๋ฐ์ดํŠธ:

์นดํ…Œ๊ณ ๋ฆฌ:

ํƒœ๊ทธ: ,


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


๐Ÿ“”

๋Œ“๊ธ€๋‚จ๊ธฐ๊ธฐ