Created
November 7, 2019 20:21
-
-
Save 123tris/d660a1258248d2bc2e7d1a2a056e22a1 to your computer and use it in GitHub Desktop.
A statemachinebehaviour to toggle rootmotion when entering or exiting animation states in Unity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class UpdateRootMotion : StateMachineBehaviour | |
{ | |
public bool onStateEnter; | |
public bool applyRootMotionOnEnter; | |
public bool onStateExit; | |
public bool applyRootMotionOnExit; | |
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) | |
{ | |
if (onStateEnter) | |
animator.applyRootMotion = applyRootMotionOnEnter; | |
} | |
public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) | |
{ | |
if (onStateExit) | |
animator.applyRootMotion = applyRootMotionOnExit; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment