我正在做一个昼夜循环。我已经把那部分写下来了,但是我需要在定向光通过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;
}
}
}
1条答案
按热度按时间cngwdvgl1#
在这一行中,lightRotation永远不会超过360:
因为它在帧之间没有增加。它只是被设置为基本上代表旋转增量的值。你应该检查你的实际变换旋转:
也可以考虑看看Mathf.MoveTowardsAngle函数。它可能更适合你的任务。