Android 设备时跳转大小不同

Different sizes of jump when Android device

我创建了一个类似 Infinite Runner 的游戏,它在 Unity 5Game 选项卡 中正常运行,但在 android当我进行跳跃时,设备的高度从未如此。

[更新 JhohnPoison 的回答]

Note: App tested on Android 4.4.2 and 5.0
Note 2: Some values are added in inspector.

实现跳跃的函数

void FixedUpdate () {
    CheckPlayerInGround();
    MakeJump();
    animator.SetBool("jump", !steppingDown);
}

void CheckPlayerInGround(){
    steppingDown = Physics2D.OverlapCircle(GroundCheck.position, 0.2f, whatIsGround);
}

void MakeJump(){
    if(Input.touchCount > 0){

        if((Input.GetTouch(0).position.x < Screen.width / 2) && steppingDown){
            if(slide == true){
                UpdateColliderScenarioPosition(0.37f);
                slide = false;
            }
            audio.PlayOneShot(audioJump);
            audio.volume = 0.75f;
            playerRigidbody2D.AddForce(new Vector2(0, jumpPower * Time.fixedDeltaTime));
        }
    }
}

您遇到的错误与 运行 游戏的帧率有关。您拥有的帧速率越高,调用更新的频率就越高(最大 60fps)。因此可以对 body.

施加不同大小的力

当你处理物理时,你应该在 FixedUpdate 中完成所有工作并使用 Time.fixedDeltaTime 来缩放你的力(而不是使用常量“7”)。

void FixedUpdate () {
    CheckPlayerInGround();
    MakeJump();
    animator.SetBool("jump", !steppingDown);
}

void CheckPlayerInGround(){
    steppingDown = Physics2D.OverlapCircle(GroundCheck.position, 0.2f, whatIsGround);
}

void MakeJump(){
    if(Input.touchCount > 0){

        if((Input.GetTouch(0).position.x < Screen.width / 2) && steppingDown){
            if(slide == true){
                UpdateColliderScenarioPosition(0.37f);
                slide = false;
            }
            audio.PlayOneShot(audioJump);
            audio.volume = 0.75f;
            playerRigidbody2D.AddForce(new Vector2(0, jumpPower * Time.fixedDeltaTime)); // here's a scale of the force
        }
    }
}

更多信息: http://docs.unity3d.com/ScriptReference/MonoBehaviour.FixedUpdate.html http://docs.unity3d.com/ScriptReference/Time-fixedDeltaTime.html