Ric*_*rdo 0 unity-game-engine unity5
我创建了一个像Infinite Runner这样的游戏,它在Unity 5的Game选项卡中正常运行,但在Android设备上,当我执行Jump时,它从来没有相同的高度.
[与JhohnPoison回复更新]
注意:在Android 4.4.2和5.0上测试应用程序
注意2:在检查器中添加了一些值.
跳转的功能
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));
}
}
}
Run Code Online (Sandbox Code Playgroud)
您遇到的错误与正在运行的帧率游戏有关.您拥有更高的帧速率,更频繁的更新将被调用(最大60fps).因此,可以对身体施加不同的力.
当您使用物理时,您应该在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
}
}
}
Run Code Online (Sandbox Code Playgroud)
更多信息:http : //docs.unity3d.com/ScriptReference/MonoBehaviour.FixedUpdate.html http://docs.unity3d.com/ScriptReference/Time-fixedDeltaTime.html