[Unity学习随笔4/29] 在跳跃前后水平方向参数的状态锁
-
不建议将太多脚本塞进状态机的behavior, 不好查bug
-
直接关联祖先(PlayerHandle, 其下绑定有模型、操纵模型的脚本等), 如尽量不要放在第二层级(如模型本体),减少级联的层数
在jump trigger被触发后, FSMOnEnter向上层发送OnJump的讯息
jump结束后, FSMExitEnter向上层发送ExitJump的讯息
public class FSMOnEnter : StateMachineBehaviour
{
public string[] onEnterMessage;
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
foreach (var msg in onEnterMessage)
{
animator.gameObject.SendMessageUpwards(msg);//发送到上层组件
}
}
}
public class FSMExitEnter : StateMachineBehaviour
{
public string[] onExitMessage;
override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
foreach (var msg in onExitMessage)
{
animator.gameObject.SendMessageUpwards(msg);
}
}
}
在人物跳跃前后水平方向参数的处理
inputEnabled: 使人物跳起来后无法乱飞,
lockPlanar使水平移动的参数被锁死,这样在跳完后仍会保持跳的瞬间水平方向移动的参数(方向,速度...)
private bool lockPlanar = false;
void update(){
...
if(lockPlanar == false)
{
//人物水平移动
//planarVec = pi.Dmag * model.transform.forward * walkSpeed * (pi.run ? runMultiplier : 1.0f);
}
...
}
public void OnJump()
{
pi.inputEnabled = false;
lockPlanar = true;
//print("jump trigger!");
}
public void ExitJump()//结束跳跃
{
pi.inputEnabled = true;
lockPlanar = false;
//print("jump over!");
}
本文来自博客园,作者:泥烟,CSDN同名, 转载请注明原文链接:https://www.cnblogs.com/Knight02/p/16255356.html