How to use OnStateMachineEnter function in StateMachineBehaviour?
I look up document and other link,but still don't know how to use OnStateMachineEnter function. I write code in OnStateMachineEnter and put on the state,but it didn,t work. Anyone can give me a small demo or a picture?
here is my code
public class AnimatorRunBehaviour : StateMachineBehaviour
{
private float m_walkspeed = 2f;
private float m_runspeed = 5f;
private Transform playerTransform;
public override void OnStateMachineEnter(Animator animator, int stateMachinePathHash)
{
playerTransform = animator.gameObject.transform;
Debug.Log("<color=red>look at this</color>");
}
}
I will be very appreciate if anyone can guide me a little.
Answer by rockear · Mar 06, 2019 at 03:55 AM
I know why OnStateMachineEnter do not trigger....Pay attention on the name of the event. OnStateMachineEnter is just triggering on transition from someone to statemachine. for example...Sub-StateMachine...I just place StateMachineBehaviour on the sub-StateMachine...OnStateMachineEnter is triggered.
Your answer
Follow this Question
Related Questions
Is there a possibility to reuse substate machines in other animator? 0 Answers
8 way directional 2D attack animation? 0 Answers
Mecanim, get state percent complete when a transition occurs? 0 Answers
Blend Trees with NavMeshAgent 0 Answers
Animator Controller sets default values even if Write Defaults is disabled 0 Answers