GroundWarning.cs

A component that controls a ground decal warning effect. It animates the decal scale and color over a lifetime, fading out and destroying the GameObject when time exceeds Lifetime.

File Access
using Sandbox;

public sealed class GroundWarning : Component
{
	[Property] public Decal Decal { get; set; }
	[Property] public Color ColorA { get; set; } = Color.Red;
	[Property] public Color ColorB { get; set; } = Color.Yellow;
	[Property] public float FullAlpha { get; set; } = 1f;
	[Property] public float Lifetime { get; set; } = 2f;

	private TimeSince _timeSinceSpawn;

	protected override void OnStart()
	{
		base.OnStart();

		_timeSinceSpawn = 0f;
	}

	protected override void OnUpdate()
	{
		Decal.Scale = Utils.Map( _timeSinceSpawn, 0f, Lifetime, 3f, 3.5f, EasingType.SineOut );

		var alpha = Utils.MapReturn( _timeSinceSpawn, 0f, Lifetime, 0f, FullAlpha, EasingType.SineOut );
		Decal.ColorTint = Color.Lerp( ColorA, ColorB, 0.5f + Utils.FastSin( _timeSinceSpawn * 24f ) * 0.5f ).WithAlpha( alpha );

		if ( _timeSinceSpawn > Lifetime )
			GameObject.Destroy();
	}
}