SpitterBlinkEffect.cs

A small Component that drives a blink/fade effect for a spitter model. It advances an animation sequence frame, lerps the renderer tint alpha over a 1 second lifetime, and destroys the parent GameObject when finished.

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