新人求问,怎么保证跳跃的及时反应啊?我按空格他有时跳有时候不
unity2d吧
全部回复
仅看楼主
level 3
新人求问,怎么保证跳跃的及时反应啊?
我按空格他有时跳有时候不跳
2020年10月18日 09点10分 1
level 2
1、定义一个全局变量
private bool isPressJumpKey;//是否按了跳跃按钮
2、添加/更改Update()方法
void Update()
{
if (Input.GetButtonDown("Jump"))
{
isPressJumpKey = true;
}
}
3、在Movement()中
void Movement()
{
......
// 跳跃
if (isPressJumpKey && coll.IsTouchingLayers(ground))
{
isPressJumpKey = false;
rb.velocity = new Vector2(rb.velocity.x,jumpforce * Time.fixedDeltaTime);
animate.SetBool("jumping",true);
}
}
原因请移步:https://blog.csdn.net/candycat1992/article/details/22927713第四点让Input能够正确工作
2021年04月10日 09点04分 4
非常感谢
2021年04月12日 08点04分
感谢
2021年08月18日 08点08分
感谢大佬,大佬我还有个问题就是当人物跳起来的时候下落到地面还是会跳起来而且我没按空格这种怎么解决?
2022年02月27日 00点02分
感谢大佬,大佬我还有个问题就是当人物跳起来的时候下落到地面还是会跳起来而且我没按空格这种怎么解决?
2022年02月27日 00点02分
level 2
不要把跳跃的函数放在fixupdate里
2021年09月13日 05点09分 5
update是每帧执行,fixupdate是固定时间执行
2021年09月13日 05点09分
@fang_chu 感谢
2021年09月14日 06点09分
感谢!
2022年05月15日 11点05分
大赞
2022年07月12日 06点07分
1