C# 速度表指针统一旋转

C# 速度表指针统一旋转,c#,android,unity3d,C#,Android,Unity3d,我正在制作一个移动汽车游戏,我想让手机的传感器为车速表的指针设置动画。我希望它从指向0的破折号旋转到最大点 指针指向最小值: 指针指向最大值: 指针指向最小值时的旋转为222 in Z,指向最大值时的旋转为-43 ,当我将下面的脚本连接到指针时,它会从最小值旋转到最大值。但逆时针方向,当达到最大值时停止,不会根据我手机的加速计读数移动 using System.Collections; using System.Collections.Generic; using UnityEngine;

我正在制作一个移动汽车游戏,我想让手机的传感器为车速表的指针设置动画。我希望它从指向0的破折号旋转到最大点

指针指向最小值:

指针指向最大值:

指针指向最小值时的旋转为222 in Z,指向最大值时的旋转为-43 ,当我将下面的脚本连接到指针时,它会从最小值旋转到最大值。但逆时针方向,当达到最大值时停止,不会根据我手机的加速计读数移动

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

public class RotationControl : MonoBehaviour
{
    static float minAnlge = 222.0F;
    static float maxAngle = -43.0F;
    static RotationControl thisSpeedo;

    // Use this for initialization
    void Start()
    {
        thisSpeedo = this;
    }
    void Update()
    {
        float ang = Mathf.LerpAngle(222, -43, Time.time);

        float z = Input.acceleration.x;
        if (z != 0)
        {
            thisSpeedo.transform.eulerAngles = new Vector3(0, 0, ang);
        }
    }
}
当我将最后一行中的ang变量更改为-ang时,它从最小值开始顺时针旋转,但没有达到最大值,它停在下图所附的点上

针停止的角度:


指针不更新其移动,当到达第三幅图像中的点时停止。

FYI,这是毫无意义的:
thisSpeedo=this
将在所有上下文中始终引用“this object”(也有例外,但它处理委托、lambda和其他奇怪的东西,而您没有使用这些)。i、 e.
this.transform.eulerAngles=新向量3(0,0,ang)可以正常工作。非常感谢您的帮助。