I have stuck in a logical problem I have a third party package of DayNight. It takes hours input(24-hour-format) to show dayNight effects in scene

My code is to transform 12 hours clock cycle into 24 hours is

if (todsky.Cycle.Hour >= 0 && todsky.Cycle.Hour < 11.97)
                var degree = 360 - hourniddle.transform.eulerAngles.z;
                var degreeToMintues = degree * 2;       //multiply each degree with 2 to get correct minutes
                ConvertMinutesToHours(degreeToMintues); //
            else if (todsky.Cycle.Hour > 11.97 && todsky.Cycle.Hour < 23.97)

                var degree = 360 - hourniddle.transform.eulerAngles.z; // as rotation is anti-clock getting rever degree
                var degreeToMintues = degree * 2; //multiply each degree with 2 to get correct minutes
                var MintuestTo24HoursMintueCoverstion = 720 + degreeToMintues; //add 720 mintues into current minute in order to get 24-hour-format

 void ConvertMinutesToHours(float mintues) {
        result = TimeSpan.FromMinutes(mintues);
        Debug.LogWarning(result.Hours + ":" + result.TotalHours + ":" + result.Minutes + ":" + result.TotalMinutes);
        todsky.Cycle.Hour = (float) result.TotalHours;
        Debug.LogWarning("setted hours : " + todsky.Cycle.Hour);

But it is not working correctly . have made a clock GUI(360-degree) and as you know it only show 12 digits-format not 24. I am getting clock needle movement which can be change through mouse drag. Needle z position up to 320 degree which means one degree is equal to 2 minutes and i am taking it as input from GUI. I write below code to integrate my clock needle with my DayNight package in order to integrate GUI with package and passing hour parameter into the package but it not working correctly. Problem is that else condition is skipping.

  • \$\begingroup\$ I don't understand the reason for the conversion. Surely you have some concept of time of day in your game, which might be realLifeTime * 10 or something, so can't you just update that in your loop and feed that into the day/night cycle code? \$\endgroup\$ – Droppy Jul 22 '16 at 6:07

I'm not sure if I understand the question completely but here goes:

Converting the clock from 12h and 24h:

The 12 hour clock is basically the 24h clock limited to 12:

12h_time.hours = 24h_time.hours % 12;

To convert the 12h clock to 24h you need to know if it is morning or afternoon:

24h_time.hours = (morning?12h_time.hours:12h_time.hours+12);

Now from what I understand you have a GUI element clock that you want the player to be able to drag the hands and time will change accordingly. To achieve that, use 720 degrees scale. If the player keeps dragging the hands of the clock, just keep the internal measurement between 0 and 720 degrees. If the clock is in the lower 360 degrees, it's morning, else it's the afternoon.

You already seem to be able to draw the clock based on 2 degrees per minute; so this still applies and I guess no code sample is needed there.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.