using UnityEngine; using System.Collections; using StateMachine; public class Example : StateMachineBehaviour { public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { Debug.Log("Entering state " + stateInfo.fullPathHash); } public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { Debug.Log("Exiting state " + stateInfo.fullPathHash); } void Start () { StateMachineBehaviour[] behaviours = new StateMachineBehaviour[2]; behaviours[0] = new StateMachineBehaviour(); behaviours[0].AddAnyTransition(() => Debug.Log("State has changed")); behaviours[1] = new StateMachineBehaviour(); behaviours[1].AddAnyTransition(() => Debug.Log("State has changed")); AnimatorStateMachine stateMachine = new AnimatorStateMachine(); stateMachine.states = new AnimatorState[2]; stateMachine.states[0] = new AnimatorState(); stateMachine.states[0].motion = new UnityEditor.AnimationClip(); stateMachine.states[0].behaviours = behaviours; stateMachine.states[1] = new AnimatorState(); stateMachine.states[1].motion = new UnityEditor.AnimationClip(); stateMachine.states[1].behaviours = behaviours; AnimatorStateMachine parentStateMachine = animator.parentStateMachine; parentStateMachine.AddStateMachine(stateMachine); } }In this example, two states are created with an "any" transition that logs a message whenever the state changes. These transitions are added with the AddAnyTransition method. It should be noted that the package library for this example is Unity's StateMachine library.