Hey all,
I have a script to change the Position of the Sun based on the real Time. Now i have Buttons to change the hour and minutes.
When i start the Scene in GameMode, i can change the value of hour and minutes in the inspector manually and the Sun is changing his position. But using the Buttons only changes the values in the inspector but my Sun is not chaning his position
I have a Light GameObject with the Sun Script :
with hour and minutes
[SerializeField]
[Range(0, 24)]
public int hour;
[SerializeField]
[Range(0, 60)]
public int minutes;
if the ray hits the button hour_up it should increase the hour by one. Well it changes the value in the inspector but the sun position doesnt change
i tried to disable the sun script to change the value, but when i enable it again it still doesnt change the sun position. Only when i use my mouse to enable it again in the inspector, then the sun is chaning his position.
someone got an idea?
Your time variable which seems to actually drive the position of your sun only gets updated in OnValidate(). Since you’re setting the hour field directly, OnValidate() is not being called. Perhaps try changing the time with your SetTime() method instead of setting the hour directly. That way OnValidate will be called.
This is part of why Unity’s “default” of using public fields everywhere is bad. You often end up exposing a bit too much about the internals of your classes than you really should.