Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Jacky2611 · May 16, 2016 at 01:48 PM · c#arraydaycycle

Repeatedly lerp through array for day night cycle

Hi everybody ! I recently switched from Java to C# and am currently working on a few assets I plan to use in a later project. Inspired by one of the unity stories I decided to try to write my own daynight cycle, which should be easily controllable through a custom editor. So far I got the basics down, finished the most important parts of my custom editor and rotated the sun 360 degrees once to test if I calculated my time (float 0-1) correctly.

However, to make it really user friendly I want my user to be able to define checkpoints that define sun position, brightness, cloud speed,... (which are all stored in serializeable TimeOfDay objects) at specific times. My DayCycler should then calculate all the values between them. And this is where I am stuck. Currently I have these two classes:

 using UnityEngine;
 using System.Collections;
 using System;
 
 public class DayCycler : MonoBehaviour {
 
     #region object references & setup
         public int dayDuration;
 
         public Light sun;
         public Material atmosphereGradient;
         public FogVolume fogVolume;
         public Material horizonClouds;
         public Light moon;
     #endregion
 
     //used to change the day length by other scripts.(weather, magic?)
     public float timeMultiplier=1.0f;
 
     public TimeOfDay currentTimeOfDay;
 
     public TimeOfDay[] timesOfDay;
 
     // Use this for initialization
     void Start () {
         currentTimeOfDay = new TimeOfDay();
         currentTimeOfDay.time = 0;
         currentTimeOfDay.name = "Automatic";
         
     }
     
     // Update is called once per frame
     void Update () {
         UpdateCurrentTimeOfDay(currentTimeOfDay.time);
 
         UpdateScene();
 
         currentTimeOfDay.time += (Time.deltaTime / dayDuration) * timeMultiplier;
         if (currentTimeOfDay.time >= 1) currentTimeOfDay.time = 0;
     }
 
     private void UpdateCurrentTimeOfDay(float time)
     {
         if (timesOfDay.Length <= 1) return;
 
         //update all variables in currentTimeOfDay depending on the time
 
         //HOW???
     }
 
     private void UpdateScene()
     {
         // TODO Write UpdateScene() once time of day is working 
     }
 }

and:

 using UnityEngine;
 using System.Collections;
 using System;
 
 [Serializable]
 public class TimeOfDay{
 
     public String name;
     public float time;
 
     public Vector3 sunRotation;
     public Color sunColor;
 
     //and so on...
 }

I considered to simply look for the two closest values to the current time in the array and then use their distance to the current time to calculate my values, but that would be kind of 'flat'. Has anyone any ideas how I could make this work?

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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

C# declaring an array of transform arrays 1 Answer

C# Set Current Array GameObject to Active 1 Answer

How to check for an empty array? 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