Class Speedometer
This class is used to keep track of the current state of a vehicle.
Namespace: YACC
Assembly: .dll
Syntax
public class Speedometer
Remarks
It is used to store the current state of the engine, brakes, steering, etc. It is also used to retrieve the current speed of the vehicle.
This class is also used to store the current state of the vehicle's wheels, this is used to retrieve the average RPM of all the wheels or the average RPM of all the powered wheels.
Examples
Initialize the class on your controller, then use it to store your informations:
using UnityEngine;
using YACC;
public class CarController : MonoBehaviour {
public Speedometer speedometer;
void Update() {
speedometer.SetInfo(kmh, gear, RPM);
}
}
Then retrieve your info for displaying it, for example using TMP.
using TMPro;
using UnityEngine;
using YACC;
public class Speedometer : MonoBehaviour {
public CarController carController;
public TextMeshProUGUI text;
void Update() {
text.text = carController.speedometer.ToString();
// Or access the properties directly
text.text = string.Format("{0} RPM\n{1} kmh\n{2} Gear", carController.speedometer.rpm, carController.speedometer.kmh, carController.speedometer.gear);
}
}
Fields
Name | Description |
---|---|
gear | The current gear of the vehicle. |
kmh | The current speed of the vehicle in kilometers per hour. |
mph | The current speed of the vehicle in miles per hour. |
rpm | The current RPM of the engine. |
torque | The current torque of the engine. |
Methods
Name | Description |
---|---|
SetInfo(float, string, float, float) | Set the current state of the vehicle. |
ToString() | Outputs a standardized formatted string with RPM, kmh and gear. |