2017-06-13 35 views
-1

当我的pnj正在运行(按下右键),并尝试跳转pnj跳转。但很少,我怎么能解决这个问题?统一3d跳转很短

这是没有问题的时候我让按右边的按钮,但我希​​望做一个游戏没有失败,我想在IO正在运行跳,thanks¡

void Update() { 
     if (Input.GetKeyDown (KeyCode.Space)) { 
      if (corriendo) { 
       if (enSuelo || !dobleSalto) { 
        GetComponent<Rigidbody2D>().velocity = new Vector2 (GetComponent<Rigidbody2D>().velocity.x, 0); 
        GetComponent<Rigidbody2D>().AddForce(Vector2.up * fuerzaSalto); 
        if (!dobleSalto && !enSuelo){ 
         dobleSalto=true; 
        } 
       } 
       corriendo = true; 
      } 
     } 

     if ((enSuelo || !dobleSalto) && Input.GetKeyDown (KeyCode.Space)) { 
      GetComponent<Rigidbody2D>().velocity = new Vector2 (GetComponent<Rigidbody2D>().velocity.x, 0); 
      GetComponent<Rigidbody2D>().AddForce(Vector2.up * fuerzaSalto); 
      if (!dobleSalto && !enSuelo){ 
       dobleSalto=true; 
      } 
     } 

     if (Input.GetKey (KeyCode.RightArrow) && enSuelo==true) { 
      if (velocidad > 17) { 
       velocidad = 17; 
      } 

      GetComponent<Rigidbody2D>().velocity = new Vector2 (GetComponent<Rigidbody2D>().velocity.x, 0); 
      GetComponent <Rigidbody2D>().AddForce (Vector2.right * velocidad); 
      velocidad++; 
     } else { 
      if (velocidad > 1) { 
       velocidad--; 
      } else { 
       velocidad = 0; 
      } 

     } 
    } 

回答

1

尝试添加一个额外的变量在AddForce(Vector2.right * velocidad * jumpFactor)

在那里你可以给increFactor一个值,所以你可以修改跳转的长度。