我正在制作昼夜循环。我有那个部分,但我需要在它通过 360 度后将定向光的 X 旋转值重置为 0,因为其他代码取决于 0 到 360 之间的值。
我尝试过使用几种不同的方法来重置旋转。到目前为止,没有人重置它。它继续旋转超过 360 度。这是我目前的剧本。
public class NewBehaviourScript : MonoBehaviour
{
Vector3 lightRotation = Vector3.zero;
public float degreePerSecond = .6f;
Vector3 lightReset = Vector3.zero;
void Update()
{
transform.Rotate(lightRotation, Space.World);
lightRotation.x = degreePerSecond * Time.deltaTime;
if(lightRotation.x >= 360)
{
transform.eulerAngles = lightReset;
}
}
}
这条线的lightRotation永远不会超过360度:
if(lightRotation.x >= 360)
因为它在帧之间没有增加。它只是被设置为一个基本上代表旋转增量的值。你应该检查你的实际变换旋转:
if(transform.eulerAngles.x >= 360)
还可以考虑查看 Mathf.MoveTowardsAngle 函数。它可能更适合您的任务。