Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using UnityEngine;
- using UnityEngine.Rendering.PostProcessing;
- public class VolumeBlendAnimation : MonoBehaviour
- {
- [Tooltip("Assign a volume that has effects set up on it\n\nThey need to be at full intensity")]
- public PostProcessVolume volume;
- [Tooltip("In case the volume should be disabled during edit mode, enable this checkbox to automatically enable it when entering play mode")]
- public bool enableVolumeOnAwake;
- public float fadeTime = 1f;
- [Header("Debug")]
- [Range(0f, 1f)]
- public float progress;
- void OnEnable()
- {
- if(enableVolumeOnAwake) volume.enabled = true;
- StartCoroutine(Fade(false));
- }
- private void OnDisable()
- {
- StartCoroutine(Fade(true));
- }
- IEnumerator Fade(bool invert)
- {
- var elapsedTime = 0f;
- while (elapsedTime < fadeTime)
- {
- elapsedTime += Time.deltaTime;
- SetProgress((invert ? 1f-(elapsedTime / fadeTime) : (elapsedTime / fadeTime)));
- yield return null;
- }
- }
- private void SetProgress(float t)
- {
- progress = Mathf.Clamp01(t);
- volume.weight = progress;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement