SpitterBlinkEffect.cs

A small game component that makes a spitter model blink/fade out. It advances the model animation time each frame, fades the renderer tint alpha from its starting value to zero over a 1s lifetime, and destroys the GameObject when the lifetime expires.

Native Interop
using Sandbox;

public sealed class SpitterBlinkEffect : Component
{
	[Property] public SkinnedModelRenderer ModelRenderer { get; set; }

	public float AnimTime { get; set; }

	private Color _startingColor;

	private TimeSince _timeSinceSpawn;
	private float _lifetime;

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

		_startingColor = ModelRenderer.Tint;

		_timeSinceSpawn = 0f;
		_lifetime = 1f;
	}

	protected override void OnUpdate()
	{
		ModelRenderer.SceneModel.CurrentSequence.Time = AnimTime;

		ModelRenderer.Tint = ModelRenderer.Tint.WithAlpha( Utils.Map( _timeSinceSpawn, 0f, _lifetime, _startingColor.a, 0f, EasingType.Linear ) );

		if( _timeSinceSpawn > _lifetime )
		{
			GameObject.Destroy();
		}
	}
}