1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- using System.Collections;
- using System.Collections.Generic;
- using Unity.VisualScripting;
- using UnityEditor.Experimental;
- using UnityEngine;
- public class SunMovement : MonoBehaviour
- {
- // Start is called before the first frame update
- public float rotationSpeed = 30f;
- public Transform rotateObj;
- public Transform targetObj;
- //public Transform targetCamera;
- public Light rotateLight;
- public Material daySkybox;
- public Material nightSkybox;
- void Start()
- {
- int hour = System.DateTime.Now.Hour;
- float rotateAngle = (12 - hour) * 13;
- //print(rotateAngle);
- if (hour < 6 || hour >= 18)
- {
- // night time
- //rotateLight.color = new Color(0, 0, 0.5f, 1);
- rotateLight.intensity = 0.65f;
- rotateLight.spotAngle = 50;
- //rotateLight.type = LightType.Spot;
- rotateLight.transform.rotation = Quaternion.Euler(50,180,0);
- UnityEngine.RenderSettings.skybox = nightSkybox;
- UnityEngine.RenderSettings.ambientIntensity = 0.3f;
- UnityEngine.RenderSettings.reflectionIntensity = 0.4f;
- // 狗狗创建灯光
- var dogLight = GameObject.Find("Dog Light").GetComponent<Light>();
- dogLight.intensity = 1.2f;
- }
- else
- {
- // day time
- UnityEngine.RenderSettings.skybox = daySkybox;
- UnityEngine.RenderSettings.ambientIntensity = 0.6f;
- UnityEngine.RenderSettings.reflectionIntensity = 0.8f;
- rotateLight.intensity = 1.2f;
- rotateObj.RotateAround(targetObj.transform.position, Vector3.forward, rotateAngle);
- }
- DynamicGI.UpdateEnvironment();
- //Debug.Log(rotateObj.transform.position);
- }
- // Update is called once per frame
- //void Update()
- //{
-
- //}
- }
|