SunMovement.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using Unity.VisualScripting;
  4. using UnityEditor.Experimental;
  5. using UnityEngine;
  6. public class SunMovement : 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 Transform targetCamera;
  13. public Light rotateLight;
  14. public Material daySkybox;
  15. public Material nightSkybox;
  16. void Start()
  17. {
  18. int hour = System.DateTime.Now.Hour;
  19. float rotateAngle = (12 - hour) * 13;
  20. //print(rotateAngle);
  21. if (hour < 6 || hour >= 18)
  22. {
  23. // night time
  24. //rotateLight.color = new Color(0, 0, 0.5f, 1);
  25. rotateLight.intensity = 0.7f;
  26. rotateLight.spotAngle = 50;
  27. UnityEngine.RenderSettings.skybox = nightSkybox;
  28. UnityEngine.RenderSettings.ambientIntensity = 0.3f;
  29. UnityEngine.RenderSettings.reflectionIntensity = 0.2f;
  30. }
  31. else
  32. {
  33. // day time
  34. UnityEngine.RenderSettings.skybox = daySkybox;
  35. UnityEngine.RenderSettings.ambientIntensity = 0.9f;
  36. UnityEngine.RenderSettings.reflectionIntensity = 1f;
  37. rotateObj.RotateAround(targetObj.transform.position, Vector3.forward, rotateAngle);
  38. }
  39. DynamicGI.UpdateEnvironment();
  40. //Debug.Log(rotateObj.transform.position);
  41. }
  42. // Update is called once per frame
  43. void Update()
  44. {
  45. }
  46. }