当前位置:   article > 正文

解决unity动画系统中多次按键之后trigger触发多次的问题_resettrigger unity

resettrigger unity

在unity动画系统中,例如用trigger控制人物跳跃动画,当你快速按下相应按键时,可能trigger会触发多次,例如:

解决方法如下:

在ground状态下新增一个名为FSMClearSignals的脚本,代码如下

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class FSMClearSignals : StateMachineBehaviour {
  5. public string[] clearAtEnter;
  6. public string[] cleatAtExit;
  7. // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
  8. override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
  9. {
  10. foreach (var signal in clearAtEnter)
  11. {
  12. animator.ResetTrigger(signal);//重置trigger
  13. }
  14. }
  15. // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
  16. //override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
  17. //
  18. //}
  19. // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
  20. override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
  21. {
  22. foreach (var signal in clearAtEnter)
  23. {
  24. animator.ResetTrigger(signal);//重置trigger
  25. }
  26. }
  27. // OnStateMove is called right after Animator.OnAnimatorMove(). Code that processes and affects root motion should be implemented here
  28. //override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
  29. //
  30. //}
  31. // OnStateIK is called right after Animator.OnAnimatorIK(). Code that sets up animation IK (inverse kinematics) should be implemented here.
  32. //override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
  33. //
  34. //}
  35. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/98294
推荐阅读
相关标签
  

闽ICP备14008679号