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 Magnomous · Aug 04, 2013 at 03:05 PM · javascriptlight

Day-night changing via rotating Directional Light

Hello, I am trying to make rotating Directional Light for changing 2 skyboxes depending on transform.rotation.x value, but it doesn't work. It is ignoring IF/ELSE statement. Anyone know how could I make it? Here is the script for better understanding:

 #pragma strict
 
 var daySpeed : float;
 var DaySkybox : Material;
 var NightSkybox : Material;
 
 RenderSettings.skybox = NightSkybox;
 
 function Start() {
     daySpeed = 0.1;
 }
 
 function Update() {
 
 transform.Rotate(daySpeed, 0, 0);
 
 if(transform.rotation.x > 0 && transform.rotation.x < 270) {
     RenderSettings.skybox = DaySkybox;
 }
 
 else{
     RenderSettings.skybox = NightSkybox;
 }
 
 }
 
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 Magnomous · Aug 04, 2013 at 03:08 PM 0
Share

forgot mentioned, that it should rotate until 360 degrees, then set value to 0 and doing this process again...

1 Reply

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

Answer by Hyperion · Aug 04, 2013 at 06:49 PM

Might I suggest not using a rotation? That will cause trees to stay 'alight'. Here's code for intensity switching.

 //Duration of day
 var duration : float= 500.0;//day is going to change ULTRA slowly
 
 function Update() {
     // argument for cosine
     var phi : float = Time.time / duration * 2 * Mathf.PI;
    
      // get cosine and transform from -1..1 to 0..1 range
     var amplitude : float = Mathf.Cos( phi ) * 0.5 + 0.5;
     
     // set light color
     light.intensity = amplitude;
 }


Then you could change your sky box based on intensity.

Comment
Add comment · Show 6 · 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 DaveA · Aug 04, 2013 at 07:03 PM 0
Share

Your 'suggestion' is a good answer, not a comment.

avatar image Hyperion · Aug 04, 2013 at 09:25 PM 0
Share

@DaveA Thank you, and @$$anonymous$$agnomous if my answer mostly solved your problem, please accept it. If you have any questions, please let me know.

avatar image Magnomous · Aug 05, 2013 at 06:35 AM 0
Share

Thank you for help, but I wonder how to make day not so long. I tried editing duration variable, but doesn't matter if it is 0.00001 or 5000, day is always too long.

avatar image Hyperion · Aug 05, 2013 at 06:55 AM 0
Share

Hmm, that's really queer. I've managed to make lights flash using this script...... Just wondering, when you put 5000 in, did you type it as a float? (5000.0) But I don't think putting a big number in would help..... And I'm guessing you tried 1.0... OOOOHHH! Ok, basically the duration originally should be 1.0 all the way to 8.0. Try every single number between and including those, and tell me the results.

avatar image Magnomous · Aug 05, 2013 at 08:10 AM 0
Share

It works, now I can mark your answer as correct, thank you, man! :-)

Show more comments

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

17 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

Related Questions

Help with GuiText flickering code. 1 Answer

Day Night Cycle Script Not Working? 1 Answer

How do I loop my light animation is javascript? 1 Answer

Changing scene messes up lights 6 Answers

Light problems 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