UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"change skybox in game play by light intensity"
public class ChangingSkyboxByDayAndNight : MonoBehaviour, ISaveable { public Material afternoonSkybox; public Material nightSkybox; Light light; public float lightMultiplier; void Start() { light = gameObject.GetComponent<Light>(); StartCoroutine(ChangeTimeOfDay()); } void UpdateSkybox() { if(light.intensity > 0.5) { RenderSettings.skybox = afternoonSkybox; } else { RenderSettings.skybox = nightSkybox; } } IEnumerator ChangeTimeOfDay() { while(light.intensity > 0.2f) { light.intensity -= lightMultiplier; UpdateSkybox(); yield return new WaitForSeconds(10); } } public object CaptureState() { return light.intensity; } public void RestoreState(object state) { if(light == null) { light = gameObject.GetComponent<Light>(); } light.intensity = (float)state; } }