ludumdare50/Assets/Scripts/BlurFade.cs
Jason Durand 01 179a3f7d22 Blur fade!
2022-04-03 16:01:49 -04:00

29 lines
662 B
C#

#nullable enable
using System.Collections;
using System.Collections.Generic;
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;
}
}