A quick tutorial on how to fade UI elements, apply glitch effects, and control timing in Unity.
📜 Get the Script: VFXAnimator.cs on GitHub
VFXAnimator is a C# script designed for Unity that automates the fading
of CanvasGroup and Image components. It features:
AnimationCurve.
1. Create an empty GameObject in your Unity scene and attach the VFXAnimator script.
2. In the Inspector, assign:
CanvasGroup components you wish to fade (e.g., UI panels).Image components you want to fill (e.g., radial wipe, progress bars).AnimationCurve if you want non-linear fading.
Fading In:
Call PlayFadeIn() from another script or a UI button click:
public class SampleUsage : MonoBehaviour
{
public VFXAnimator animator;
void Start()
{
// Fade everything in when the scene loads
animator.PlayFadeIn();
}
}
Fading Out:
Similarly, call PlayFadeOut(). You can optionally pass a callback to run after the sequence finishes:
animator.PlayFadeOut(() =>
{
Debug.Log("All elements faded out!");
// You could unload a scene or disable objects here
});
Timing Settings
- startingDelay: Wait time before fade in.
- exitDelay: Wait time before fade out.
- delayBetweenElements: How long to wait before starting the next element’s fade.
- fadeDuration: How long each fade/ fill animation lasts.
Glitch Effect
- enableGlitchEffect: Toggle flickering on previously faded elements.
- glitchDuration: How long each flicker lasts.
- glitchRepeats: Number of times each previous element flickers.
- randomGlitchOrder: Flicker prior elements in random order.
- glitchAlphaMin / glitchAlphaMax: Range of alpha used for flickering.
The testVisibility bool (exposed in the Inspector)
allows you to toggle fade in/out at runtime without extra scripting.
Flip it to true to auto-fade in, or false to auto-fade out.
This is perfect for dialing in the right speed, delays, and glitch values on the fly.
The VFXAnimator script is a simple approach to orchestrate UI fades and glitchy visuals.
We hope this tutorial helps you integrate smooth, attention-grabbing animations in your Unity project. Enjoy creating awesome UI experiences!