I have a script 'DayNightCycle' which is attached to the main directional light which over the course of 20 minutes rotates the light to give a simple day night cycle, this works great for me.
However I wanted to be able to set the light rotation for each scene, so I added the following code:
[Range(0.0f, 360f)]
public int LevelStartTime = 90;
private void OnValidate()
{
transform.eulerAngles = new Vector3(
LevelStartTime,
transform.eulerAngles.y,
transform.eulerAngles.z
);
}
This gives me a 0-360 slider which allows me to set the start light rotation and see it in the editor. However when the value is slid between 90 and 270 the light keeps 'flipping' on the 'y' rotation. For example when the slider is on 177 the transform rotation value shows 3, and when its on 234 transform shows -54. However if you manually type in those same numbers in my LevelStartTime the transform correctly has the same number!
![alt text][1]
Any ideas whats going on?
[1]: /storage/temp/164702-annotation-2020-08-03-213755.png
↧