VEHICLE SCRIPTING • INTER-SCRIPT COMMUNICATION
EngineController does not contain a definition for 'currentSpeed'
Occurs when an audio script or UI speedometer tries to read engineController.currentSpeed, but the variable is declared private or named differently.
1
Expose a Public Read-Only Property in EngineController.cs
Open your EngineController.cs (or CarController.cs) and add this public property:
EngineController.cs (C#)
using UnityEngine;
public class EngineController : MonoBehaviour
{
private Rigidbody rb;
private void Awake()
{
rb = GetComponent<Rigidbody>();
}
// ✅ EXPOSE THIS PROPERTY:
// Calculates real-time speed in meters per second (m/s) or km/h
public float currentSpeed => rb != null ? rb.linearVelocity.magnitude : 0f;
public float CurrentSpeedKmh => currentSpeed * 3.6f;
}