47 lines
916 B
C#
47 lines
916 B
C#
using UnityEngine;
|
|
using UnityEngine.AzureSky;
|
|
|
|
public class LightingByNight : MonoBehaviour
|
|
{
|
|
private Light light;
|
|
|
|
public Vector2 timeToSwitchOnLight = new Vector2(17f, 5f);
|
|
|
|
public Material litLight;
|
|
|
|
private AzureTimeController azureTimeController;
|
|
|
|
private void Start()
|
|
{
|
|
azureTimeController = Object.FindObjectOfType<AzureTimeController>();
|
|
light = GetComponent<Light>();
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
if (azureTimeController == null || light == null)
|
|
{
|
|
return;
|
|
}
|
|
if (azureTimeController.GetTimeOfDay().x > timeToSwitchOnLight.x || azureTimeController.GetTimeOfDay().x <= timeToSwitchOnLight.y)
|
|
{
|
|
if (!light.enabled)
|
|
{
|
|
light.enabled = true;
|
|
if (litLight != null)
|
|
{
|
|
litLight.EnableKeyword("_EMISSION");
|
|
}
|
|
}
|
|
}
|
|
else if (light.enabled)
|
|
{
|
|
light.enabled = false;
|
|
if (litLight != null)
|
|
{
|
|
litLight.DisableKeyword("_EMISSION");
|
|
}
|
|
}
|
|
}
|
|
}
|