ui/richtext/bases/RichTextColorLerp.cs

A UI RichText behavior that continuously lerps the font color between two Colors over time. It increments internal time each Tick, computes a ping-pong factor between 0 and 1, and sets Style.FontColor to the interpolated color.

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;
	}
}