- Home /
 
How to impliment a 10 minute day clock, and tie it to a directional light rotation.
Hi everyone, I'm new at this but learning.
Much as the question says, I'm looking at creating a clock above the minimap I have in my gui, which shows time in the game, as I will have time related events in the game world, but in it a day passes at roughly 10 minute cycles.
How do I tear gametime away from my system time which it seems to be going to automatically, and display that in a timer. (Think, the Sims, for example).
In addition, I'm trying to link this to a day night cycle, and I thiiink (tentativley) that I have that rotation sorted, but its rotating on a 24hour cycle as it is tied to my system time.
Any help would be appreciated =)
Answer by Matt SandBox · Dec 20, 2013 at 11:06 PM
Just incase anyone sees this in the future and needs a solution. My workaround was as follows
 using UnityEngine;
 using System.Collections;
 
 public class GameTime : MonoBehaviour {
     public Transform Sun;
     public float dayCycleInMinutes = 4;
 
     public const float SECOND = 1;
     public const float MINUTE = 60 * SECOND;
     public const float HOUR = 60 * MINUTE;
     public const float DAY = 24 * HOUR;
     public const float MONTH = 30 * DAY;
     public const float YEAR = 12 * MONTH;
     
     private const float DEGREES_PER_SECOND = 360 / DAY;
     
     private float _degreeRotation;
     
     private float _timeofDay;
     
     // Use this for initialization
     void Start () {
         _timeofDay = 0;
         _degreeRotation = DEGREES_PER_SECOND * DAY / (dayCycleInMinutes * MINUTE);
          Time.timeScale = 1.0f;
     }
     
     // Update is called once per frame
     void Update () {
         
         Sun.Rotate(new Vector3(_degreeRotation, 0, 0) * Time.deltaTime);
     
 
             
         _timeofDay += Time.deltaTime;
         Debug.Log(_timeofDay);
             
         
     }
 }
 
               This ties the rotation to a gameobject based over that time. The time was displayed on a GuiText clock which operated independently.
 var nextSecond : float = 25;
 
 var second: int;
 var hour =0.0f;
 var day = 0.0f;
 var month = 0.0f;
 var year= 0.0f;
 
 
 
 function Update () {
       
         if(nextSecond > 0) {
 
         nextSecond -= Time.deltaTime;
 
         }
         
         else {
 
         nextSecond = 25;
 
         hour += 1;
         
         }
     
      if (hour >= 24){
 
         hour=0;
 
         day +=1;
 
         }
     
      if (day >= 30){
 
         day=0;
 
         month +=1;
 
         }
         
          if (month >= 12){
 
         month=0;
 
         year +=1;
 
         }
  
  guiText.text = "  " + day + "      " + month + "      " + year;
  
  }
 
               All of these were found on the Unity Wiki or other answers on here.
Answer by Zaeran · Nov 05, 2013 at 12:11 PM
If you don't want to update a time variable every frame (or every second, using coroutines), You could possibly use modulo-division to get a 10 minute time from your 24hr cycle
Answer by Matt SandBox · Dec 20, 2013 at 11:06 PM
Just incase anyone sees this in the future and needs a solution. My workaround was as follows
 using UnityEngine;
 using System.Collections;
 
 public class GameTime : MonoBehaviour {
     public Transform Sun;
     public float dayCycleInMinutes = 4;
 
     public const float SECOND = 1;
     public const float MINUTE = 60 * SECOND;
     public const float HOUR = 60 * MINUTE;
     public const float DAY = 24 * HOUR;
     public const float MONTH = 30 * DAY;
     public const float YEAR = 12 * MONTH;
     
     private const float DEGREES_PER_SECOND = 360 / DAY;
     
     private float _degreeRotation;
     
     private float _timeofDay;
     
     // Use this for initialization
     void Start () {
         _timeofDay = 0;
         _degreeRotation = DEGREES_PER_SECOND * DAY / (dayCycleInMinutes * MINUTE);
          Time.timeScale = 1.0f;
     }
     
     // Update is called once per frame
     void Update () {
         
         Sun.Rotate(new Vector3(_degreeRotation, 0, 0) * Time.deltaTime);
     
 
             
         _timeofDay += Time.deltaTime;
         Debug.Log(_timeofDay);
             
         
     }
 }
 
               This ties the rotation to a gameobject based over that time. The time was displayed on a GuiText clock which operated independently.
 var nextSecond : float = 25;
 
 var second: int;
 var hour =0.0f;
 var day = 0.0f;
 var month = 0.0f;
 var year= 0.0f;
 
 
 
 function Update () {
       
         if(nextSecond > 0) {
 
         nextSecond -= Time.deltaTime;
 
         }
         
         else {
 
         nextSecond = 25;
 
         hour += 1;
         
         }
     
      if (hour >= 24){
 
         hour=0;
 
         day +=1;
 
         }
     
      if (day >= 30){
 
         day=0;
 
         month +=1;
 
         }
         
          if (month >= 12){
 
         month=0;
 
         year +=1;
 
         }
  
  guiText.text = "  " + day + "      " + month + "      " + year;
  
  }
 
               All of these were found on the Unity Wiki or other answers on here.
Answer by White-Chocolate-Development · Nov 25, 2015 at 12:19 PM
using UnityEngine; using System.Collections;
public class TimeOfDay : MonoBehaviour {
 public float time = 0.5f;
 void Update () {
     this.transform.Rotate (Vector3.right * time * Time.smoothDeltaTime);
 }
 
               }
Your answer
 
             Follow this Question
Related Questions
Unity2D Day and Night Cycle 0 Answers
Timed event Question 2 Answers
Changing lighting/skybox based on Computer Time? 1 Answer
Digital clock 1 Answer
Day/Night Skybox 1 Answer