A UI rich text behavior that continuously lerps the font color between two colors over a duration, updating Style.FontColor each Tick.
using Sandbox;
using System;
public class RichTextColorLerp : RichTextBase
{
public virtual Color ColorLerpStart => Color.White;
public virtual Color ColorLerpEnd => Color.White;
public virtual float LerpDuration => 2f;
private float _time = 0f;
public override void Tick()
{
_time += RealTime.Delta;
// Calculate lerp factor (0 to 1 and back)
float t = (_time % LerpDuration) / LerpDuration;
t = t * 2f; // Make it go 0->1->0
if ( t > 1f ) t = 2f - t;
// Lerp between colors
var lerpedColor = Color.Lerp( ColorLerpStart, ColorLerpEnd, t );
Style.FontColor = lerpedColor;
}
}