FX , VO, fixy
This commit is contained in:
34
Assets/Scripts/VolumeFadeOut.cs
Normal file
34
Assets/Scripts/VolumeFadeOut.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user