运动似乎不稳定,但 FPS 很好

Movement seem choppy but FPS is good

所以我刚写完我的动作脚本,我的游戏似乎帧率很低。我启动 fraps,发现我的游戏是 运行 60FPS。可能是什么问题?顺便说一句,这也是一款自上而下的角色扮演游戏。 如果有帮助,这是我的移动脚本:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour {
Vector2 _playerPosition;
public GameObject Player;
// Use this for initialization
void Start () {
    _playerPosition = Vector2.zero;
}

// Update is called once per frame
public float speed = 3f;
void Update()
{
if (Input.GetKey(KeyCode.W))
{
    transform.position += Vector3.up * speed * Time.deltaTime;
}

if (Input.GetKey(KeyCode.S))
{
   transform.position += Vector3.down * speed * Time.deltaTime;
}

if (Input.GetKey(KeyCode.D))
{
    transform.position += Vector3.right * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.A))
{
    transform.position += Vector3.left * speed * Time.deltaTime;
    }
}

}

观看 YouTube 教程对于学习有关 Unity 的新知识确实很有帮助。在此处查看 4 min,您将看到我将尝试像这样进行转换的代码:

if (Input.GetKey(KeyCode.D)){
    transform.Translate(speed * Time.deltaTime,0f,0f); //x,y,z
}

我在问题的评论中提出的建议是,我会将您的 if 语句放在更新之外的方法中,并像这样每秒调用该方法,Unity 也有很好的 question/answers 社区

InvokeRepeating("MyMethod", 1f, 1f); //I believe this is every second

我还建议对您的代码进行更改,以减少行数并允许左、右、上、下的移动键以及 A、D、W、S 和我们的操纵杆移动。

void Update(){
    transform.Translate(speed * Input.GetAxis("Horizontal") * Time.deltaTime, 0f, 
                      speed * Input.GetAxis("Vertical") * Time.deltaTime)
}