Hard days night

If you have any ideas please help as I am stumped…

I have a day / night cycle which works based on the Sun’s transform rotation.

The scene always starts at midday, the position the sun is set to in the editor.

However, with a level loader preceding it, the cycle can start anytime, depending on how long I let the preceding Level loader scene run! If I leave the start menu on screen for a few minutes then press start, I get a dark sky!

The sun moves with a simple rotate transform and should always start in the same position on level load (I am loading the complete level by Application.LoadLevel (1))

What could cause my day/cycle to start before the level has loaded!???

On inspection, the sun does keep the right transform. It is the sky changing color that is going out of sync.

Guessing here, but are you using Time.time to set the color change?

If so, try Time.timeSinceLevelLoad instead.

yes, I’m using
var t = Mathf.PingPong (Time.time, Skyduration) / Skyduration;

camera.backgroundColor = Color.Lerp (color1, color2, t);

Would that cause the problem? I assumed everything starts from scratch except global vars when a scene has loaded… thanks for the pointer, will check…

simply replacing Time.time in the code with Time.timeSinceLevelLoad seems to do the trick… thanks!

Sure! :smile: