y 轴上的相机旋转值按时间获得高浮点数

Camera Rotation value on y axis get high float number by time

我尝试创建自由外观相机我按照 YouTube 上的教程进行操作一切正常,除了我注意到存储在浮点变量中的关于 y 轴的旋转值角度值正在继续累积我尝试夹紧它但它会导致不良行为我也尝试 mathf.repeat 如果它大于 360,我尝试将角度归零,但这会在相反的方向创建另一个即时旋转,我使用我认为的 += 运算符如果我没记错的话会导致这个

我的问题是这会影响我针对移动设备的总体性能

如果影响性能,我该如何处理?

非常感谢您的帮助

using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class Camera : MonoBehaviour



{

    public Transform target;

    public float destotarget;

    public float sensetivity;

    public float smoothTime;

    public float yaw;

    public float pitch;

    public Vector2 minandmax = new Vector2(34, 54);

    public Vector3 currnetrot;

    public Vector3 velocitysmooth;


    // Update is called once per frame
    void LateUpdate()
    {
        yaw += Input.GetAxis("Mouse X") * sensetivity;
        pitch += Input.GetAxis("Mouse Y") * sensetivity;

        pitch = Mathf.Clamp(pitch, minandmax.x, minandmax.y);

        currnetrot = Vector3.SmoothDamp(currnetrot, new Vector2(pitch, yaw), ref velocitysmooth, smoothTime);
        transform.eulerAngles = currnetrot;

        transform.position = target.position - transform.forward * destotarget;

    }
}

这应该不会对性能产生太大影响,但唯一知道的方法是分析:

  1. https://docs.unity3d.com/Manual/profiler-profiling-applications.html
  2. https://blog.theknightsofunity.com/mobile-optimization-unity-profiler/