C# 嗨,我的2D游戏角色传送得稍微高一点,然后他下降得非常慢,当我按下跳跃按钮时,他就像一片叶子

C# 嗨,我的2D游戏角色传送得稍微高一点,然后他下降得非常慢,当我按下跳跃按钮时,他就像一片叶子,c#,unity3d,2d,C#,Unity3d,2d,如果我一直按按钮,它就会一直向上。当我删除左右移动的脚本时,效果很好,但是当我添加它时,我遇到了这个问题。 这是我的密码 ` { 刚体2d rb float dirX; float jumpForce = 300f; float moveSpeed = 5f; void Start() { rb = GetComponent<Rigidbody2D>(); } void Update() { dirX = CrossPlatformInputManage

如果我一直按按钮,它就会一直向上。当我删除左右移动的脚本时,效果很好,但是当我添加它时,我遇到了这个问题。 这是我的密码

` { 刚体2d rb

float dirX;
float jumpForce = 300f;
float moveSpeed = 5f;







void Start()
{
    rb = GetComponent<Rigidbody2D>();
}
void Update()
{
    dirX = CrossPlatformInputManager.GetAxis("Horizontal");
    rb.velocity = new Vector2(dirX * 10, 0);

    

    if (CrossPlatformInputManager.GetButtonDown("Jump"))
        DoJump();
}  
    void DoJump()
    {
        if (rb.velocity.y == 0)
            rb.AddForce(new Vector2(0, jumpForce), ForceMode2D.Force);
    } 
    
}`
float-dirX;
浮力=300f;
浮动速度=5f;
void Start()
{
rb=GetComponent();
}
无效更新()
{
dirX=CrossPlatformInputManager.GetAxis(“水平”);
rb.velocity=新矢量2(dirX*10,0);
if(CrossPlatformInputManager.GetButtonDown(“跳转”))
DoJump();
}  
void DoJump()
{
if(rb.velocity.y==0)
rb.AddForce(新矢量2(0,跳跃力),ForceMode2D.Force);
} 
}`
rb.velocity=新矢量2(dirX*10,rb.velocity.y)


rb.AddForce(新矢量2(rb.velocity.x,jumpForce),ForceMode2D.Force)

是的,只需要做这些改变

rb.velocity=新矢量2(dirX*10,rb.velocity.y)


rb.AddForce(新矢量2(rb.velocity.x,jumpForce),ForceMode2D.Force)

我做了更改,但现在它甚至不会跳转,可能会删除“if(rb.velocity.y==0)”并使用不同的东西。这两个答案为什么完全相同,对它的评论也完全相同?我做了更改,但现在它甚至不会跳转给我一些时间考虑一下