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
-1
Question by glenohumeral13 · Jun 21, 2014 at 03:32 PM · daycycleburgzergarcade

How to start the day at day (Burgzerg Arcade)?

So if any of you are familiar with Burgzerg Arcade on YouTube (or are just good with code), hopefully you can figure out what my problem is. When I start the day, the day skyboxes are up, which is good. However, the sun isn't. Instead it comes up during the night.

 using UnityEngine;
 using System.Collections;
 
 public class GameTime : MonoBehaviour {
     public enum TimeOfDay {
         Idle,
         SunRise,
         SunSet
     }
     public Transform[] sun;
     private Sun[] _sunScript;
 
     public float sunRise;
     public float sunSet;
     public float skyboxBlendModifier;
 
     public float dayCycleInMinutes=1;
 
     private const float SECOND = 1;
     private const float MINUTE = 60 * SECOND;
     private const float HOUR = 60 * MINUTE;
     private const float DAY = 24 * HOUR;
 
     private const float DEGREES_PER_SECOND = 360 / DAY;
 
     private float _degreeRotation;
 
     private float _timeOfDay;
 
     private float _dayCycleInSeconds;
 
     private TimeOfDay _tod;
     private float _noonTime; //this is the time of day when it is noon
     private float _morningLength;
     private float _eveningLength;
 
     // Use this for initialization
     void Start () {
         _tod = TimeOfDay.Idle;
         _dayCycleInSeconds = dayCycleInMinutes * MINUTE;
 
         RenderSettings.skybox.SetFloat("_Blend",0);
 
         _sunScript = new Sun[sun.Length];
         for (int cnt = 0; cnt < sun.Length; cnt++) {
             Sun temp = sun[cnt].GetComponent<Sun>();
 
             if (temp == null) {
                 Debug.LogWarning("Sun script not found");
                 sun[cnt].gameObject.AddComponent<Sun>();
                 temp = sun[cnt].GetComponent<Sun>();
             }
             _sunScript[cnt] = temp;
         }
         _timeOfDay = 0; //starts the day off at 0 seconds, original is 0
         _degreeRotation = DEGREES_PER_SECOND * DAY / (_dayCycleInSeconds);
 
         sunRise *= _dayCycleInSeconds;
         sunSet *= _dayCycleInSeconds;
         _noonTime = _dayCycleInSeconds / 2;
         _morningLength = _noonTime - sunRise;    //the length of the morning in seconds
         _eveningLength = sunSet - _noonTime;    //the length of the evening in seconds
 
         SetupLighting (); //setup lighting to maxvalues on start
     }
     
     // Update is called once per frame
     void Update () {
         for(int cnt = 0; cnt < sun.Length; cnt ++) 
         sun [cnt].Rotate (new Vector3(_degreeRotation, 0, 0) * Time.deltaTime);
 
         _timeOfDay += Time.deltaTime;
 
         if (_timeOfDay > _dayCycleInSeconds) 
                         _timeOfDay -= _dayCycleInSeconds;
 
     //    Debug.Log (_timeOfDay);
         if (_timeOfDay > sunRise && _timeOfDay < _noonTime) {
             AdjustLighting(true);
                 } else if(_timeOfDay > _noonTime && _timeOfDay < sunSet) {
             AdjustLighting(false);
                 }
         if (_timeOfDay > sunRise && _timeOfDay < sunSet && RenderSettings.skybox.GetFloat ("_Blend") < 1) {
                         _tod = GameTime.TimeOfDay.SunRise;
                         BlendSkybox ();
                 } else if (_timeOfDay > sunSet && RenderSettings.skybox.GetFloat ("_Blend") > 0) {
                         _tod = GameTime.TimeOfDay.SunSet;
                         BlendSkybox ();
                 } else {
             _tod = GameTime.TimeOfDay.Idle;
                 }
             }
     private void BlendSkybox() {
         float temp = 0;
 
         switch (_tod) {
         case TimeOfDay.SunRise:
             temp = (_timeOfDay - sunRise) / _dayCycleInSeconds * skyboxBlendModifier;
             break;
         case TimeOfDay.SunSet:
             temp = (_timeOfDay - sunSet) / _dayCycleInSeconds * skyboxBlendModifier;
             temp = 1 - temp;
             break;
 
                 }
 
         RenderSettings.skybox.SetFloat("_Blend",temp);
 
         Debug.Log (temp);
 
         }
 
         private void SetupLighting() {
         for (int cnt = 0; cnt < _sunScript.Length; cnt++) {
             if(_sunScript[cnt].giveLight){
                 sun[cnt].GetComponent<Light>().intensity = _sunScript[cnt].maxLightBrightness;
             }
                 }
     }
 
     private void AdjustLighting (bool brighten) {
         if (brighten) {
                         float pos = (_timeOfDay - sunRise) / _morningLength; // get the position of the sun in the morning sky
                         for (int cnt = 0; cnt < _sunScript.Length; cnt++) {
                                 if (_sunScript [cnt].giveLight) {
                                         _sunScript [cnt].GetComponent<Light> ().intensity = _sunScript [cnt].maxLightBrightness * pos;
                                 }
                         }
                 }
         else {
             float pos = (sunSet - _timeOfDay) / _eveningLength; // get the position of the sun in the evening sky
             for (int cnt = 0; cnt < _sunScript.Length; cnt++) {
                 if (_sunScript [cnt].giveLight) {
                     _sunScript [cnt].GetComponent<Light> ().intensity = _sunScript [cnt].maxLightBrightness * pos;
                 }
             }
                 }
                                     }
 }

I know, it's really long, but it'd would be so great if someone could help me out. I have already tried editing the _timeOfDay variable in the Start function, as well as switch the skybox positions around.

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

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

BurgZergArcade Unity tutorial 19-20 errors. 0 Answers

DayNight Shadows Problems 0 Answers

How do you get the 24 Hour Time from rotation on the x axis? 1 Answer

Variable target in 'Targetting system' error. 1 Answer

Why is fading not smooth? 0 Answers


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