So i created this day light script:
[ExecuteInEditMode]
public class LightingManager : MonoBehaviour
{
[SerializeField] private Light DirectionLight;
[SerializeField] private LightingPreset Preset;
[SerializeField, Range(0, 24)] private float TimeOfDay;
private void Update()
{
if (Preset == null)
return;
if (Application.isPlaying)
{
TimeOfDay += Time.deltaTime;
TimeOfDay %= 24;
UpdateLighting(TimeOfDay / 24f);
}
else
{
UpdateLighting(TimeOfDay / 24f);
}
}
private void UpdateLighting(float timePercent)
{
RenderSettings.ambientLight = Preset.AmbientColor.Evaluate(timePercent);
RenderSettings.fogColor = Preset.FogColor.Evaluate(timePercent);
if (DirectionLight != null)
{
DirectionLight.color = Preset.DirectionalColor.Evaluate(timePercent);
DirectionLight.transform.localRotation = Quaternion.Euler(new Vector3((timePercent * 360f)-90f, -170f, 0));
}
}
private void OnValidate()
{
if (DirectionLight != null)
return;
if (RenderSettings.sun != null)
{
DirectionLight = RenderSettings.sun;
}
else
{
Light[] lights = GameObject.FindObjectsByType<Light>();
foreach(Light light in lights)
{
if(light.type == LightType.Directional)
{
DirectionLight = light;
return;
}
}
}
}
}
But i also wanted to make that at night you get a moon and during the day you get a sun, but i have no idea how i could do that