Class DigitalGauge
Text-based digital gauge for displaying numerical or string values with optional progress bar visualization. Supports smoothing for numerical displays and flexible formatting. Requires child GameObjects named "Readout" (Text) and optionally "Line" (Image) for the progress bar.
Namespace: NWH.VehiclePhysics2.VehicleGUI
Assembly: NWH.VehiclePhysics2.dll
Syntax
[RequireComponent(typeof(Text))]
public class DigitalGauge : MonoBehaviour
Fields
format
Format string for numerical values using C# standard numeric format strings. Examples: "0" = no decimals, "0.0" = one decimal, "0.00" = two decimals, "000" = zero-padded to 3 digits.
Declaration
[Tooltip("Numerical value formatting.")]
public string format
Field Value
| Type | Description |
|---|---|
| string |
gaugeType
Determines the display mode and which value property to use. Numerical mode uses numericalValue with formatting and smoothing. Textual mode uses stringValue directly (useful for gear indicators).
Declaration
[Tooltip("Should the stringValue or numericalValue be used. String value is useful for e.g. gear (R, N, 1, 2, 3) and numerical\r\nfor\r\nspeed, RPM or similar.")]
public DigitalGauge.GaugeType gaugeType
Field Value
| Type | Description |
|---|---|
| DigitalGauge.GaugeType |
maxValue
Maximum value for calculating progress bar percentage. Only relevant when showProgressBar is enabled. For example, set to 8000 for an RPM gauge that goes to 8000 RPM.
Declaration
[Tooltip("Maximum value that the gauge can display. Only used if showProgressBar enabled.")]
public float maxValue
Field Value
| Type | Description |
|---|---|
| float |
numericalSmoothing
Smoothing factor for numerical value transitions. Higher values create smoother, more gradual changes. 0 = instant updates, 1 = maximum smoothing. Recommended: 0.3-0.7 for speed/RPM displays to reduce jumpiness.
Declaration
[Range(0, 1)]
[Tooltip("Time over which the numerical value will be smoothed.")]
public float numericalSmoothing
Field Value
| Type | Description |
|---|---|
| float |
numericalValue
The numerical value to display. Only used when gaugeType is Numerical. This value will be formatted according to the format string and smoothed according to numericalSmoothing.
Declaration
[Tooltip("Numerical value that will be displayed on the gauge.")]
public float numericalValue
Field Value
| Type | Description |
|---|---|
| float |
showProgressBar
Enables a visual progress bar (horizontal line) that fills based on the percentage of numericalValue relative to maxValue. Requires a child GameObject named "Line" with an Image component. Only works with gaugeType set to Numerical.
Declaration
[Tooltip("Should the progress line/bar be displayed for better visualization?")]
public bool showProgressBar
Field Value
| Type | Description |
|---|---|
| bool |
stringValue
The string value to display. Only used when gaugeType is Textual. Displayed as-is without any formatting or smoothing.
Declaration
[Tooltip("String value that will be displayed on the gauge.")]
public string stringValue
Field Value
| Type | Description |
|---|---|
| string |
unit
Unit text appended after the value, such as "km/h", "mph", "RPM", "°C", etc. A space is automatically added between the value and unit.
Declaration
[Tooltip("Unit displayed after the value, e.g., km/h.")]
public string unit
Field Value
| Type | Description |
|---|---|
| string |