35 lines
898 B
C#
35 lines
898 B
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using UnityEngine.Rendering;
|
|
|
|
public class VolumeFadeOut : MonoBehaviour
|
|
{
|
|
public Volume volume; // Przypisz w Inspectorze lub ustaw dynamicznie
|
|
public float fadeDuration = 1.0f; // Czas wygaszania w sekundach
|
|
|
|
/// <summary>
|
|
/// Funkcja do odpalenia z eventu, np. z przycisku lub triggera.
|
|
/// </summary>
|
|
public void FadeAndDisableVolume()
|
|
{
|
|
if (volume != null)
|
|
StartCoroutine(FadeOutCoroutine());
|
|
}
|
|
|
|
private IEnumerator FadeOutCoroutine()
|
|
{
|
|
float startWeight = volume.weight;
|
|
float elapsed = 0f;
|
|
|
|
while (elapsed < fadeDuration)
|
|
{
|
|
elapsed += Time.deltaTime;
|
|
volume.weight = Mathf.Lerp(startWeight, 0f, elapsed / fadeDuration);
|
|
yield return null;
|
|
}
|
|
|
|
volume.weight = 0f;
|
|
volume.enabled = false;
|
|
}
|
|
}
|