using EVP; using UnityEngine; namespace Script { using UnityEngine; public class CarGearControl : MonoBehaviour { private VehicleController vehicleController; private VehicleStandardInput vehicleStandardInput; public int currentGear = 0; // 当前挡位 public float[] gearSpeeds = { 0f, 20f, 40f, 60f }; // 每个挡位的最大速度 public float xx; float steerInput, throttleInput, brakeInput, handbrakeInput; void Start() { vehicleController = GetComponent(); vehicleStandardInput = GetComponent(); } void Update() { // 检测并更新挡位 CheckAndUpdateGear(); // 根据当前挡位设置车辆速度 SetVehicleSpeed(gearSpeeds[currentGear]); vehicleController.steerInput = 0; vehicleController.throttleInput = xx; vehicleController.brakeInput = 0; vehicleController.handbrakeInput = 0; Debug.Log($"{steerInput}--{throttleInput}--{brakeInput}--{handbrakeInput}"); // vehicleStandardInput.SetThrottleValue(xx); // SetSpeedBasedOnValue(1); } void CheckAndUpdateGear() { if (Input.GetKeyDown(KeyCode.Alpha1)) currentGear = 1; if (Input.GetKeyDown(KeyCode.Alpha2)) currentGear = 2; if (Input.GetKeyDown(KeyCode.Alpha3)) currentGear = 3; if (Input.GetKeyDown(KeyCode.Alpha0)) currentGear = 0; // 假设0为空挡 } void SetVehicleSpeed(float maxSpeed) { // 在这里,你需要根据你的车辆控制系统来调整速度。 // 以下是一个假设的方法,你可能需要根据EVP5的API来修改它。 vehicleController.maxSpeedForward = maxSpeed; vehicleController.throttleInput = 1; } } }