Advertisement
Guest User

Light dimming with sunset setting

a guest
Aug 20th, 2014
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1. //Here is how i made the light dimming go syncronised with when the skyboxes blend:
  2. //I have included my code that i changed!
  3. //NOTE: In update, remove the call for AdjustLighting(false) !! Otherwise it will still happen with the old timing
  4.     private void SkyboxBlend(){
  5.         float temp = 0;
  6.         switch(_tod){
  7.             case TimeOfDay.Sunrise:
  8.                 temp = (_TimeOfDay - Sunrise) / DayCycleInSeconds * SkyboxBlendModifier;;
  9.                 break;
  10.             case TimeOfDay.Sunset:
  11.                 temp = (_TimeOfDay - Sunset) / DayCycleInSeconds * SkyboxBlendModifier;
  12.                 temp = 1 - temp;
  13.                 //I added the code below and swapped the pos variable to temp
  14.                 RenderSettings.ambientLight = new Color(
  15.                     AmbientLightMin.r + AmbientLightMax.r * temp,
  16.                     AmbientLightMin.g + AmbientLightMax.g * temp,
  17.                     AmbientLightMin.b + AmbientLightMax.b * temp);
  18.                 Sun.GetComponent<Light>().intensity = Sun.GetComponent<Sun>().MaxLightBrightness * temp;
  19.                 //Swaped the variable for the sun too (for me im just changing one sun, if you have a for loop
  20.                 //just modify that to work!
  21.                 break;
  22.             default:
  23.                 Debug.LogWarning("Time of Day wasnt Sunrise or sunset!");
  24.                 break;
  25.         }
  26.         MainCamera.GetComponent<Skybox>().material.SetFloat("_Blend", temp);
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement