A component attached to the Gauss gun that drives a visual coil object. It exposes a Coil GameObject and a Curve property, tracks time since ammo was consumed, and on Update rotates the Coil based on a smoothed speed value derived from the Curve evaluated against the TimeSinceAmmoConsumed. It implements GaussWeapon.IGaussWeaponEvents to reset the timer when ammo is consumed.
public sealed class GaussGunEffects : Component, GaussWeapon.IGaussWeaponEvents
{
[Property]
public GameObject Coil { get; set; }
[Property]
public Curve Curve { get; set; }
TimeSince TimeSinceAmmoConsumed = 100;
float speed;
float Speed
{
get
{
speed = speed.LerpTo( Curve.Evaluate( TimeSinceAmmoConsumed, false ), Time.Delta * 10f );
return speed;
}
}
protected override void OnUpdate()
{
Coil.WorldRotation *= Rotation.From( 0, 0, Speed );
}
void GaussWeapon.IGaussWeaponEvents.OnConsumedAmmo()
{
TimeSinceAmmoConsumed = 0;
}
}