You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
685 B
28 lines
685 B
using UnityEngine; |
|
|
|
[RequireComponent(typeof(Light))] |
|
public class TOD_LightAtNight : MonoBehaviour |
|
{ |
|
public float fadeTime = 1; |
|
private float lerpTime = 0; |
|
|
|
private Light lightComponent; |
|
private float lightIntensity; |
|
|
|
protected void Start() |
|
{ |
|
lightComponent = GetComponent<Light>(); |
|
lightIntensity = lightComponent.intensity; |
|
|
|
lightComponent.enabled = TOD_Sky.Instance.IsNight; |
|
} |
|
|
|
protected void Update() |
|
{ |
|
int sign = (TOD_Sky.Instance.IsNight) ? +1 : -1; |
|
lerpTime = Mathf.Clamp01(lerpTime + sign * Time.deltaTime / fadeTime); |
|
|
|
lightComponent.intensity = Mathf.Lerp(0, lightIntensity, lerpTime); |
|
lightComponent.enabled = (lightComponent.intensity > 0); |
|
} |
|
}
|
|
|