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 greatwhiteshark17283 · Jan 01, 2014 at 10:19 PM · timechangetransitionskyday

Time of day script not working

I made a script that makes the time of day change gradually at a certain speed, but I can't get the sky color to change the right way. The variable "sky" in this script is the same material that the skybox is. The color of the sky is supposed to gradually change color and not change immediately. This is the script:

 var speed : float = 0.5; 
 var stars : GameObject;
 var day = Color(.302, .404, .808, 1);
 var night = Color.black;
 private var sunset : boolean;
 var mid = Color.red;
 var sky : Material;
 var curSky : Color;
 var smooth : float;
  
 function Update() {
     transform.Rotate(speed*Time.deltaTime,0,0);
     if(transform.rotation.eulerAngles.x < 30){
         if(sunset == true){
             curSky = Color.Lerp(day, mid,  Time.deltaTime * smooth);
         }
         if(sunset == false){
             curSky = Color.Lerp(night, mid,  Time.deltaTime * smooth);
         }
     }
     if(transform.rotation.eulerAngles.x > 30){
         if(transform.rotation.eulerAngles.x < 90){
             sunset = true;
             curSky = Color.Lerp(mid, day,  Time.deltaTime * smooth);
         }
     }
     if(transform.rotation.eulerAngles.x > 90){
         sunset = false;
         curSky = Color.Lerp(mid, night,  Time.deltaTime * smooth);
     }
     sky.color = curSky;
 }
Comment
Add comment · Show 1
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 Womrwood · Jan 02, 2014 at 12:07 AM 0
Share

It will help you to understand the problem not to solve it completely. http://answers.unity3d.com/questions/14288/can-someone-explain-how-using-timedeltatime-as-t-i.html

2 Replies

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

Answer by Vonni · Jan 02, 2014 at 12:33 AM

Think you are misunderstand how lerp works.

Time.deltaTime * smooth will be roughly the same value each frame.

 Color.Lerp(Black, White, 0) // will return black
 Color.Lerp(Black, White, 1) // will return white
 Color.Lerp(Black, White, 0.5) // will return gray

So you should include Time.time somewhere in yourscript

Comment
Add comment · Show 1 · 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 greatwhiteshark17283 · Jan 02, 2014 at 11:15 PM 0
Share

Thanks for the advice. Time.time works great. I understood how lerp works, it's that I haven't really used Time too much. If anyone else has the same problem, I'm going to put my final script below:

 var stars : GameObject;
 var day = Color(.302, .404, .808, 1);
 var night = Color.black;
 private var sunset : boolean;
 var mid = Color.red;
 var sky : $$anonymous$$aterial;
 var curSky : Color;
 var smooth : float;
 var curTime = 0.0;
 var timer = 1;
 private var days = 0;
 private var taken = 0.0;
 InvokeRepeating("TimeReset", (360/speed), (360/speed));
  
 function Update() {
     transform.Rotate(speed*Time.deltaTime,0,0);
     if(transform.rotation.eulerAngles.x < 30){
         if(sunset == true){
             timer += smooth * Time.deltaTime;
             curSky = Color.Lerp(day, mid,  smooth*(curTime - (150/speed)));
         }
         if(sunset == false){
             timer += smooth * Time.deltaTime;
             curSky = Color.Lerp(night, mid,  smooth*(curTime - (0/speed)));
             stars.SetActive(true);
         }
     }
     if(transform.rotation.eulerAngles.x > 30){
         if(transform.rotation.eulerAngles.x < 90){
             timer += smooth * Time.deltaTime;
             sunset = true;
             curSky = Color.Lerp(mid, day,  smooth*(curTime - (30/speed)));
         }
     }
     if(transform.rotation.eulerAngles.x > 90){
         timer += smooth * Time.deltaTime;
         sunset = false;
         curSky = Color.Lerp(mid, night,  smooth*(curTime - (180/speed)));
         stars.SetActive(true);
     }
     sky.color = curSky;
     if(timer > 1){
         timer = 1;
     }
     curTime = (Time.time) - taken;
 }
 function TimeReset(){
     taken = taken + Time.time;
     days = days + 1;
 }

FYI, the timer variable does nothing.

avatar image
0

Answer by White-Chocolate-Development · Nov 25, 2015 at 12:19 PM

using UnityEngine; using System.Collections;

public class TimeOfDay : MonoBehaviour {

      //This is just using the default sky-box only if the sky-box is set to procedural
 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

21 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

Related Questions

Unity2D Day and Night Cycle 0 Answers

referring to a particular material 0 Answers

Make a change every 0.02 seconds precise 1 Answer

Time elapsed between variable change? 1 Answer

Sliding between camera change 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