UnitShockVfx.cs

A Sandbox component that runs a shock visual effect, holding a ParticleEffect reference and fading its alpha over a set Lifetime using an easing curve.

Native Interop
using System;
using Sandbox;

public class UnitShockVfx : Component
{
	[Property] public ParticleEffect ParticleEffect { get; set; }

	private TimeSince _timeSinceSpawn;
	public float Lifetime { get; set; }

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

		_timeSinceSpawn = 0f;
		Lifetime = 1f;
	}

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

		ParticleEffect.Alpha = Utils.Map( _timeSinceSpawn, 0f, Lifetime, 1f, 0f, EasingType.ExpoOut );
	}
}