天津23维预案
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
687 B

using UnityEngine;
[RequireComponent(typeof(AudioSource))]
public class TOD_AudioAtNight : MonoBehaviour
{
public float fadeTime = 1;
private float lerpTime = 0;
private AudioSource audioComponent;
private float audioVolume;
protected void Start()
{
audioComponent = GetComponent<AudioSource>();
audioVolume = audioComponent.volume;
audioComponent.enabled = TOD_Sky.Instance.IsNight;
}
protected void Update()
{
int sign = (TOD_Sky.Instance.IsNight) ? +1 : -1;
lerpTime = Mathf.Clamp01(lerpTime + sign * Time.deltaTime / fadeTime);
audioComponent.volume = Mathf.Lerp(0, audioVolume, lerpTime);
audioComponent.enabled = (audioComponent.volume > 0);
}
}