PlaygroundLightControl.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class PlaygroundLightControl : MonoBehaviour
  5. {
  6. public Light directionalLight;
  7. public Material daySkybox;
  8. public Material nightSkybox;
  9. // Start is called before the first frame update
  10. void Start()
  11. {
  12. int hour = System.DateTime.Now.Hour;
  13. float dayLightY = (12 - hour) * 10;
  14. if (hour < 6 || hour >= 18)
  15. {
  16. // night time
  17. directionalLight.transform.rotation = Quaternion.Euler(60, 0, 0);
  18. directionalLight.intensity = 0.67f;
  19. UnityEngine.RenderSettings.skybox = nightSkybox;
  20. }
  21. else
  22. {
  23. // day time
  24. directionalLight.transform.rotation = Quaternion.Euler(60, dayLightY, 0);
  25. UnityEngine.RenderSettings.skybox = daySkybox;
  26. UnityEngine.RenderSettings.ambientIntensity = 0.75f;
  27. }
  28. DynamicGI.UpdateEnvironment();
  29. }
  30. // Update is called once per frame
  31. void Update()
  32. {
  33. }
  34. }