28 lines
628 B
C#
28 lines
628 B
C#
#nullable enable
|
|
using System.Collections;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering;
|
|
|
|
public class BlurFade : MonoBehaviour {
|
|
Volume volume = null!;
|
|
Coroutine? coroutine;
|
|
bool blurred;
|
|
[SerializeField] [Range(0f, 1f)]
|
|
float transitionSpeed = 0.2f;
|
|
|
|
void Awake() => volume = GetComponent<Volume>();
|
|
|
|
public void SetBlurred(bool value) {
|
|
blurred = value;
|
|
coroutine ??= StartCoroutine(BlurCoroutine());
|
|
}
|
|
|
|
IEnumerator BlurCoroutine() {
|
|
while (blurred ? volume.weight <= 1f : volume.weight >= 0f) {
|
|
volume.weight += transitionSpeed * (blurred ? 1f : -1f);
|
|
yield return null;
|
|
}
|
|
|
|
coroutine = null;
|
|
}
|
|
} |