I'm currently working on a Time of Day system, and in that system I want to be able to control at which hour SUNRISE starts, DAY start, SUNSET starts and NIGHT starts. At the moment this is possible in the system and when the "clock" hits the next start hour I start a Coroutine to start the rotating of the sun and moon. I asked this as a question but got no answer. I've tried to solve this myself without any luck at all. I'm hoping that maybe someone here could give help me how to do this?

My coroutine looks like this:



IEnumerator RotateSun(Vector3 fDegrees, float SecondsDuringTimeSet)
        Quaternion quaFromPosition = _lSunLight.transform.rotation;
        Quaternion quaToPostion = Quaternion.Euler(fDegrees);

        for (float t = 0.0f; t < 1; t += Time.deltaTime / SecondsDuringTimeSet)
            _lSunLight.transform.rotation = Quaternion.Lerp(quaFromPosition, quaToPostion, t);
            yield return null;

And as you see I pass values into that for each time I run it. This is done like this:



if (_fCurrGameHour == _fTimeStartSunrise && _bMoveSunAndMoonOnlyOnce == true)
            // Which TIMESET should it be:
            _en_CurrTimeSet = TimeSet.SUNRISE;

            // How long should the SUN move and how many which degree should it reach before that time ends
            vec3MoveSun = new Vector3(10.0f, 0, 0);
            StartCoroutine(RotateSun(vec3MoveSun, _fConvertSunriseToGTSeconds));

            // How long should the MOON move and how many which degree should it reach before that time ends
            vec3MoveMoon = new Vector3(180.0f, 0, 0);
            StartCoroutine(RotateMoon(vec3MoveMoon, _fConvertSunriseToGTSeconds));

            // Tell bool that we don't need to move the sun and moon more then once
            _bMoveSunAndMoonOnlyOnce = false;

And as I wrote this system works at the moment. However it is kind of a static system. So at the moment I need to make sure that the starting hour of the game is the sunrise hour. Otherwise my coroutine would break since it would not rotate to the correct position before the day start hour. And I can definitly not start the game close to sunset then the sun rotates the complete wrong way since it's closer to rotate the wrong way then (I assume).

So my first question is: Could I somehow make the system more dynamic? I want to be able to still set at which hours SUNRISE, DAY, SUNSET and NIGHT should start so during different season for example I could have different lengths on my day. I want to be able to change these hours in the game and then if the SUNSET would be set later the sun would start to rotate a little slower since it is supposed to take longer to reach it's SUNSET position.

Onto my second question: Would it also be possible to rewrite my coroutine so I could start the game at any hour I want and the sun would still start at the right degree rotation?

The sun will always set at the same rotation (170 degrees) and rise at the same rotation (350 degree). I just want to control the time it takes before it reaches to those rotations. Maybe I could somehow move this to my update phase instead of using a Coroutine for this? I have no clue how to change this in my system so if anyone have any ideas. Please help.