unity2d吧 关注:9,276贴子:643
  • 12回复贴,共1

新人求问,怎么保证跳跃的及时反应啊?我按空格他有时跳有时候不

只看楼主收藏回复

新人求问,怎么保证跳跃的及时反应啊?
我按空格他有时跳有时候不跳


IP属地:北京来自Android客户端1楼2020-10-18 17:08回复
    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能够正确工作


    IP属地:广西4楼2021-04-10 17:13
    收起回复
      2026-01-22 02:03:39
      广告
      不感兴趣
      开通SVIP免广告
      不要把跳跃的函数放在fixupdate里


      IP属地:四川来自Android客户端5楼2021-09-13 13:42
      收起回复