58 lines
1.3 KiB
C#
58 lines
1.3 KiB
C#
using System.Collections;
|
|
using UnityEngine;
|
|
using UnityEngine.Audio;
|
|
|
|
public class TFPCaveAudioParticle : MonoBehaviour
|
|
{
|
|
public float audioTransitionDuration = 0.6f;
|
|
|
|
public AudioMixerSnapshot open;
|
|
|
|
public AudioMixerSnapshot cave;
|
|
|
|
public ParticleSystem rain;
|
|
|
|
public float ambienceTransitionDuration = 1f;
|
|
|
|
public float caveAmbientIntensity;
|
|
|
|
public float outdoorAmbientIntensity;
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (other.gameObject.tag == "CaveTrigger")
|
|
{
|
|
cave.TransitionTo(0.6f);
|
|
InitAmbienceTransition(caveAmbientIntensity, ambienceTransitionDuration);
|
|
rain.Stop();
|
|
}
|
|
}
|
|
|
|
private void OnTriggerExit(Collider other)
|
|
{
|
|
if (other.gameObject.tag == "CaveTrigger")
|
|
{
|
|
open.TransitionTo(0.6f);
|
|
InitAmbienceTransition(outdoorAmbientIntensity, ambienceTransitionDuration);
|
|
rain.Play();
|
|
}
|
|
}
|
|
|
|
public void InitAmbienceTransition(float goalAmbience, float duration)
|
|
{
|
|
StartCoroutine(ChangeAmbience(goalAmbience, duration));
|
|
}
|
|
|
|
private IEnumerator ChangeAmbience(float goalAmbience, float duration)
|
|
{
|
|
float startAmbience = RenderSettings.ambientIntensity;
|
|
float progress = 0f;
|
|
while (progress < 1f)
|
|
{
|
|
progress = Mathf.Clamp01(progress + Time.deltaTime / duration);
|
|
RenderSettings.ambientIntensity = Mathf.Lerp(startAmbience, goalAmbience, progress);
|
|
yield return null;
|
|
}
|
|
}
|
|
}
|