HomeSunLight.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Experimental.Rendering;
  5. using UnityEngine.Rendering;
  6. public class HomeSunLight : MonoBehaviour
  7. {
  8. // Start is called before the first frame update
  9. public float rotationSpeed = 30f;
  10. public Transform rotateObj;
  11. public Transform targetObj;
  12. public Light rotateLight;
  13. public GameObject targetCamera;
  14. public Material daySkybox;
  15. public Material nightSkybox;
  16. void Start()
  17. {
  18. GameObject homeLight = GameObject.Find("Home Light");
  19. int hour = System.DateTime.Now.Hour;
  20. //hour = 7;
  21. float rotateAngle = (12 - hour) * 13;
  22. //print(rotateAngle);
  23. if (hour < 6 || hour >= 18)
  24. {
  25. // night time
  26. rotateLight.intensity = 0.1f;
  27. //targetCamera.GetComponent<Camera>().backgroundColor = new Color(22, 42, 113, 239);
  28. UnityEngine.RenderSettings.skybox = nightSkybox;
  29. UnityEngine.RenderSettings.ambientIntensity = 0.2f;
  30. UnityEngine.RenderSettings.reflectionIntensity = 0.2f;
  31. homeLight.GetComponent<Light>().intensity = 1f;
  32. }
  33. else
  34. {
  35. Debug.Log("day time");
  36. // day time
  37. rotateLight.intensity = 0.7f;
  38. //targetCamera.GetComponent<Camera>().clearFlags = CameraClearFlags.SolidColor;
  39. //targetCamera.GetComponent<Camera>().backgroundColor = new Color(139, 202, 255, 203);
  40. UnityEngine.RenderSettings.skybox = daySkybox;
  41. UnityEngine.RenderSettings.ambientIntensity = 0.9f;
  42. UnityEngine.RenderSettings.reflectionIntensity = 1f;
  43. homeLight.GetComponent<Light>().intensity = 0.4f;
  44. rotateObj.RotateAround(targetObj.transform.position, Vector3.forward, rotateAngle);
  45. }
  46. DynamicGI.UpdateEnvironment();
  47. }
  48. // Update is called once per frame
  49. void Update()
  50. {
  51. }
  52. }