Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Matt SandBox · Nov 05, 2013 at 05:20 AM · guitimeclocknightday

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 =)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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);
 }

}

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges