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 Nov 02, 2014 at 11:30 AM by ExtremePowers for the following reason:

The question is answered, right answer was found and edited into the original question.

avatar image
0
Question by ExtremePowers · Nov 01, 2014 at 09:16 PM · skyboxblendnightday

Day/Night Skybox

I have modified a script I found, my problem with the script is that the Blend doesn't apply probably even though the value is right, its like the Material.SetFloat("_Blend", Blend) Doesn't run:

 #pragma strict
     
 var TOD : float;
 public var sun : GameObject;
 var NightAmbientLight : Color;
 var DuskAmbientLight : Color;
 var MorningAmbientLight : Color;
 var MiddayAmbientLight : Color;
 var SunNight : Color;
 var SunDay : Color;
 
 var NightSkyBox : Material;
 var DaySkyBox : Material;
 var NightBlendSkybox : Material;
 var DayBlendSkybox : Material;
 
 private var skybox : Skybox;
 
 // Use this for initialization
 function Start() {
     skybox = GetComponent(Skybox);
     sun = GameObject.Instantiate(sun, Vector3.zero, Quaternion.identity);
 }
 
 var DayLength = 24.0f;
 var Hour = 0.0f;
 
 var Blend : float;
 
 function Update() {
     Hour = Mathf.Clamp(Hour, 0, 1) == 1 ? 0 : Hour;
     Hour += (Time.deltaTime / DayLength) / 60;
     
     TOD = Hour * 24;
     Blend = (Hour % (1.0f / 12.0f)) * 12.0f;
     
     sun.GetComponent(Light).transform.localEulerAngles = new Vector3((Hour * 360) - 90, 0,0);
     sun.GetComponent(Light).color = Color.Lerp(SunNight, SunDay, Hour);
         
     if (TOD > 4 && TOD < 6) {
         skybox.material = NightBlendSkybox;
         skybox.material.SetFloat("_Blend", Blend);
         RenderSettings.ambientLight = Color.Lerp(NightAmbientLight, MorningAmbientLight, Blend);
         //it is Morning
     } else if (TOD > 6 && TOD < 8) {
         skybox.material = DaySkyBox;
         skybox.material.SetFloat("_Blend", Blend);
         RenderSettings.ambientLight = Color.Lerp(MorningAmbientLight, MiddayAmbientLight, Blend);
         //it is Day
     } else if (TOD > 18 && TOD < 20) {
         skybox.material = DayBlendSkybox;
         skybox.material.SetFloat("_Blend", Blend);
         RenderSettings.ambientLight = Color.Lerp(MiddayAmbientLight, DuskAmbientLight, Blend);
            //it is Dusk
     } else if (TOD > 20 && TOD < 22) {
         skybox.material = NightSkyBox;
         skybox.material.SetFloat("_Blend", Blend);
         RenderSettings.ambientLight = Color.Lerp(DuskAmbientLight, NightAmbientLight, Blend);
         //it is Night
     }
 }
 

 
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 tanoshimi · Nov 01, 2014 at 09:47 PM 0
Share

And what's the shader assigned to the skybox material? Does it have a _Blend property?

avatar image Nebukam · Nov 02, 2014 at 04:11 AM 0
Share

So is it working yet ? If so, you should close your question ^^ Also, you could drastically shorten your else/if statement to something shorter and more readable :

  $$anonymous$$aterial sky$$anonymous$$at;

  if (TOD > 4 && TOD < 6) {            //it is $$anonymous$$orning
      sky$$anonymous$$at = NightBlendSkybox;
  } else if (TOD > 6 && TOD < 8) {     //it is Day
      sky$$anonymous$$at = DaySkyBox;         
  } else if (TOD > 18 && TOD < 20) {   //it is Dusk
      sky$$anonymous$$at = DayBlendSkybox;
  } else if (TOD > 20 && TOD < 22) {   //it is Night
      sky$$anonymous$$at = NightSkyBox;         
  }

  skybox.material = sky$$anonymous$$at;
  skybox.material.SetFloat("_Blend", Blend);
  RenderSettings.ambientLight = Color.Lerp(NightAmbientLight, $$anonymous$$orningAmbientLight, Blend);

1 Reply

  • Sort: 
avatar image
0

Answer by ExtremePowers · Nov 01, 2014 at 10:39 PM

It does, but I fixed it. It was just some weird values. Edited the code above.

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

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

Related Questions

Help with Skybox Fading 1 Answer

Day Night cycle question 1 Answer

Blend two lightmaps for day/night cycle? (terrain) 0 Answers

DayNight controller script smoothed transition 0 Answers

How to impliment a 10 minute day clock, and tie it to a directional light rotation. 4 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