在游戏视图中,相机速度是完美的,但在手机中测试时,相机速度要慢得多

In game view, the camera speed is perfect but while testing in phones the camera speed is much slower

在我的游戏中,镜头速度非常完美,正如我所希望的那样。

在手机中,测试我的游戏相机速度非常慢。我不知道如何解决这个问题,也不知道这个问题的根本原因是什么。

这是我贴在主摄像头上的脚本

public float translation;
public float highspeed;//highest speed of the camera
public float incfactor;//increasing ,multiplying number
public bool ismoving = false;

private float timer = 0f;
private Rigidbody2D dia;

private void Start()
{
    dia = GetComponent<Rigidbody2D>();
}

private void Update()
{
    if (Input.GetMouseButtonDown(0))
    {
        RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
        if (hit.collider != null)
        {

            if (hit.collider.tag == "dialogue")
            {
                Destroy(hit.collider.gameObject);
                ismoving = true;
            }
        }
    }

    if (ismoving == true)
    {
        Updatemove();
    }
}

public void Updatemove()
{
    timer += Time.deltaTime;

    if (timer > 1f && translation < highspeed)
    { //after 1 second has passed...
        timer = 0; // reset timer
        translation += incfactor; //increase speed by 0.5
    }

    transform.Translate(0, translation, 0);
}

您在 Update 中调用 Updatemove,每帧调用一次。

但比你Translate高出一个固定值translation,它帧相关(较低的帧率=>较少的调用=>较慢的移动)

你的物体将以 (translation * framerate) / seconds

的速度移动

为了消除 framerate 因素并获得稳定的、与设备无关的 translation / seconds 速度,您必须乘以 Time.deltaTime

所以应该是

public void Updatemove() 
{   
    timer += Time.deltaTime;

    if (timer > 1f && translation < highspeed) 
    { //after 1 second has passed...
        timer = 0; // reset timer
        translation += incfactor ; //increase speed by 0.5
    }

    transform.Translate(0, translation * Time.deltaTime, 0);
}

因为 Time.deltaTime 是一个非常小的值(1/framerate = 0.017(对于 60 fps)),您可能需要将 incfactor 增加或减少 [=21] =]