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 /
This question was closed Jul 13, 2014 at 04:13 AM by AlucardJay for the following reason:

Duplicate Question : http://forum.unity3d.com/threads/how-can-i-show-the-time-in-this-day-night-cycle-script.256634/

avatar image
0
Question by Stormy102 · Jul 12, 2014 at 04:54 PM · javascripttimedaycycle

How can I show the time in this Day/Night Cycle Script

Hi all!

I have a day/night script that I have modified for my own purposes. I want to be able to show the time in the top right-hand corner. I have tried numerous ways but cannot find it so it can display a time like 16:42. It always goes past 60 and is about 5 decimal places long. If anyone can either help or modify the code for me, I will be very grateful. If I need to, I can post a .unitypackage file. Here is the code:

TOD.js

 var slider : float;
 var slider2 : float;
 var Hour : float;
 private var Tod: float;
 
 var sun: Light;
 
 var speed = 50;
 
 var NightFogColor : Color;
 var DuskFogColor : Color;
 var MorningFogColor : Color;
 var MiddayFogColor : Color;
 
 var NightAmbientLight : Color;
 var DuskAmbientLight : Color;
 var MorningAmbientLight : Color;
 var MiddayAmbientLight : Color;
 
 var NightTint : Color;
 var DuskTint : Color;
 var MorningTint : Color;
 var MiddayTint : Color;
 
 var SkyBoxMaterial1 : Material;
 var SkyBoxMaterial2 : Material;
 
 var SunNight : Color;
 var SunDay : Color;
 
 //THIS WAS ADDED IN TUTORIAL NUMBER 24. It allows for changing the color that reflects of a water object.
 //Uncheck IncludeWater if you are not interested in using this.
 var Water : GameObject;
 var IncludeWater = false;
 var WaterNight : Color;
 var WaterDay : Color;
 var Hr : int;
 var Min : int = Hour / 60 * 100;
 
 function OnGUI () {
 
     if(slider >= 1.0)
     {
         slider = 0;
     }
         
     Hr = Hour;
     Min = Hour / 60 * 100;
     
     GUI.Label(Rect(Screen.width - 100, 20, 25, 100), Hr.ToString() + ":" + Min.ToString("f0"));
 
     //slider= GUI.HorizontalSlider( Rect(20,20,200,30), slider, 0,1.0);
     Hour= slider*24;
     Tod= slider2*24;
     sun.transform.localEulerAngles = Vector3((slider*360)-90, 0, 0);
     slider = slider +Time.deltaTime/speed;
     sun.color = Color.Lerp (SunNight, SunDay, slider*2);
 
 
 
     //THIS WAS ADDED IN TUTORIAL NUMBER 24. It allows for changing the color that reflects of a water object.
     //Uncheck IncludeWater if you are not interested in using this.
     if (IncludeWater == true)
     {
         Water.renderer.material.SetColor("_horizonColor", Color.Lerp (WaterNight, WaterDay, slider2*2-0.2));
     }
 
     if(slider<0.5){
         slider2= slider;
     }
     if(slider>0.5){
         slider2= (1-slider);
     }
     sun.intensity = (slider2-0.2)*1.7;
 
 
     if(Tod<4){
         //it is Night
         RenderSettings.skybox=SkyBoxMaterial1;
         RenderSettings.skybox.SetFloat("_Blend", 0);
         SkyBoxMaterial1.SetColor ("_Tint", NightTint);
         RenderSettings.ambientLight = NightAmbientLight;
         RenderSettings.fogColor = NightFogColor;
     }
     if(Tod>4&&Tod<6){
         RenderSettings.skybox=SkyBoxMaterial1;
         RenderSettings.skybox.SetFloat("_Blend", 0);
         RenderSettings.skybox.SetFloat("_Blend", (Tod/2)-2);
         SkyBoxMaterial1.SetColor ("_Tint", Color.Lerp (NightTint, DuskTint, (Tod/2)-2) );
         RenderSettings.ambientLight = Color.Lerp (NightAmbientLight, DuskAmbientLight, (Tod/2)-2);
         RenderSettings.fogColor = Color.Lerp (NightFogColor,DuskFogColor, (Tod/2)-2);
         //it is Dusk
     }
     if(Tod>6&&Tod<8){
         RenderSettings.skybox=SkyBoxMaterial2;
         RenderSettings.skybox.SetFloat("_Blend", 0);
         RenderSettings.skybox.SetFloat("_Blend", (Tod/2)-3);
         SkyBoxMaterial2.SetColor ("_Tint", Color.Lerp (DuskTint,MorningTint,  (Tod/2)-3) );
         RenderSettings.ambientLight = Color.Lerp (DuskAmbientLight, MorningAmbientLight, (Tod/2)-3);
         RenderSettings.fogColor = Color.Lerp (DuskFogColor,MorningFogColor, (Tod/2)-3);
         //it is Morning
     }
     if(Tod>8&&Tod<10){
     RenderSettings.ambientLight = MiddayAmbientLight;
     RenderSettings.skybox=SkyBoxMaterial2;
     RenderSettings.skybox.SetFloat("_Blend", 1);
     SkyBoxMaterial2.SetColor ("_Tint", Color.Lerp (MorningTint,MiddayTint,  (Tod/2)-4) );
     RenderSettings.ambientLight = Color.Lerp (MorningAmbientLight, MiddayAmbientLight, (Tod/2)-4);
     RenderSettings.fogColor = Color.Lerp (MorningFogColor,MiddayFogColor, (Tod/2)-4);
 
     //it is getting Midday
     }
 }

Any help is appreciated.

Cheers,

Stormy102

Comment
Add comment · Show 2
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 Stormy102 · Jul 12, 2014 at 05:33 PM 0
Share

Anybody got any ideas?

avatar image Stormy102 · Jul 12, 2014 at 06:11 PM 0
Share

Has anybody got any ideas?

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by MakeCodeNow · Jul 12, 2014 at 05:54 PM

In cases like this, .NET string formatting is your friend. Just use a date/time format and pass the resultant, formatted string to the GUI Label. Easy!

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

Follow this Question

Answers Answers and Comments

23 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Real-time day/night system breaks after noon 1 Answer

Execute code for a certain amount of time 1 Answer

fading between skyboxes 1 Answer

Pause button 2 Answers

Realtime Clock? (needles) 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