Class ShaderSpeedometer
A speedometer interface that display its speed via shader.
public class ShaderSpeedometer : Speedometer
Inheritance
Inherited Members
- Speedometer.speedDisplayScale
- Speedometer.speedDisplayUnit
- Speedometer.SetRawSpeed(float)
- Speedometer.ConvertRawSpeed(float, Speedometer.SpeedUnit)
Remarks
This class sets the _Speed property on a material to dynamically reflect
the actor’s current speed, enabling shader-based visual effects such as motion indicators
or speed-based animations.
This speedometer is designed with the assumption that all instances in the scene will receive speed updates from a single actor only (typically the player). If multiple actors in the scene send ActorSpeedMessage events, it will cause conflicts and unreliable readings, as all Speedometer instances will respond to messages from every actor indiscriminately. Ensure only one actor broadcasts speed updates per scene.
Methods
SetRawSpeed(float)
Sets the current raw speed sample (in meters per second) for this speedometer.
public override void SetRawSpeed(float rawSpeed)
Parameters
| Name | Type | Description |
|---|---|---|
rawSpeed | float | The actor's speed in meters per second (m/s), typically the magnitude of its velocity. |
Remarks
Implementations should convert to the configured display unit, multiply by
speedDisplayScale, and take the absolute value before updating any visuals,
Call this whenever a new speed value is available (e.g., per FixedUpdate).
Keep implementations allocation-free and fast; this may be invoked frequently.
A common pattern is:
var converted = Mathf.Abs(ConvertRawSpeed(Mathf.Max(0f, rawSpeed), speedDisplayUnit) * speedDisplayScale); // Update UI/needle/text/etc. with 'converted'