赞
踩
在unity动画系统中,例如用trigger控制人物跳跃动画,当你快速按下相应按键时,可能trigger会触发多次,例如:
解决方法如下:
在ground状态下新增一个名为FSMClearSignals的脚本,代码如下
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
-
- public class FSMClearSignals : StateMachineBehaviour {
-
- public string[] clearAtEnter;
- public string[] cleatAtExit;
-
- // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
- override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
- {
- foreach (var signal in clearAtEnter)
- {
- animator.ResetTrigger(signal);//重置trigger
- }
- }
-
- // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
- //override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
- //
- //}
-
- // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
- override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
- {
- foreach (var signal in clearAtEnter)
- {
- animator.ResetTrigger(signal);//重置trigger
- }
- }
-
- // OnStateMove is called right after Animator.OnAnimatorMove(). Code that processes and affects root motion should be implemented here
- //override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
- //
- //}
-
- // OnStateIK is called right after Animator.OnAnimatorIK(). Code that sets up animation IK (inverse kinematics) should be implemented here.
- //override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
- //
- //}
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。