using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// 首先导入 Logitech SDK /// 方法二需要用到sdk /// public class LogTest : MonoBehaviour { void Start() { } void Update() { //方向盘所有按键获取: //方法一: //该方法在unity中只能获取0-19的键位 20-24键位需要使用方法二获取 或者全部使用方法二 //if (Input.GetKeyDown(KeyCode.Joystick1Button0)) //{ // Debug.Log("KeyCode.Joystick1Button0 方向盘 X 键"); //} //方法二: if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0)) { LogitechGSDK.DIJOYSTATE2ENGINES wheel; wheel = LogitechGSDK.LogiGetStateUnity(0); for (int i = 0; i < 128; i++) { if (wheel.rgbButtons[i] == 128) { switch (i) { case 0: Debug.Log("KeyCode.Joystick1Button0 方向盘 X 键"); break; case 1: Debug.Log("KeyCode.Joystick1Button1 方向盘 □ 键"); break; case 2: Debug.Log("KeyCode.Joystick1Button2 方向盘 ○ 键"); break; case 3: Debug.Log("KeyCode.Joystick1Button3 方向盘 △ 键"); break; case 4: Debug.Log("KeyCode.Joystick1Button4 方向盘 右拨片 键"); break; case 5: Debug.Log("KeyCode.Joystick1Button5 方向盘 左拨片 键"); break; case 6: Debug.Log("KeyCode.Joystick1Button6 方向盘 R2 键"); break; case 7: Debug.Log("KeyCode.Joystick1Button7 方向盘 L2 键"); break; case 8: Debug.Log("KeyCode.Joystick1Button8 方向盘 SHARE 键"); break; case 9: Debug.Log("KeyCode.Joystick1Button9 方向盘 OPTION 键"); break; case 10: Debug.Log("KeyCode.Joystick1Butto10 方向盘 R3 键"); break; case 11: Debug.Log("KeyCode.Joystick1Button11 方向盘 L3 键"); break; case 12: Debug.Log("KeyCode.Joystick1Button12 挡位 1 挡"); break; case 13: Debug.Log("KeyCode.Joystick1Button13 挡位 2 挡"); break; case 14: Debug.Log("KeyCode.Joystick1Button14 挡位 3 挡"); break; case 15: Debug.Log("KeyCode.Joystick1Button15 挡位 4 挡"); break; case 16: Debug.Log("KeyCode.Joystick1Button16 挡位 5 挡"); break; case 17: Debug.Log("KeyCode.Joystick1Button17 挡位 6 挡"); break; case 18: Debug.Log("KeyCode.Joystick1Button18 挡位 R 挡(倒挡)"); break; case 19: Debug.Log("KeyCode.Joystick1Button19 方向盘 + 键"); break; case 20: Debug.Log("KeyCode.Joystick1Button20 方向盘 - 键"); break; case 21: Debug.Log("KeyCode.Joystick1Button21 方向盘 红色滚轮右滚 键"); break; case 22: Debug.Log("KeyCode.Joystick1Button22 方向盘 红色滚轮左滚 键"); break; case 23: Debug.Log("KeyCode.Joystick1Button23 方向盘 回车 键"); break; case 24: Debug.Log("KeyCode.Joystick1Button24 方向盘 特殊标志键 键"); break; } } } } //Horizontal Throttle Brake 这三个参数需要在 unity中 Edit - project settings - input 中设置 如下图 //方向盘转弯 float Steeringwheel = Input.GetAxis("Horizontal"); Debug.Log("方向盘转弯参数:" + Steeringwheel); //脚踏板 //油门 float throttle = Input.GetAxisRaw("YouMen"); Debug.Log("油门参数" + throttle); //刹车 float brake = Input.GetAxisRaw("ShaChe"); Debug.Log("刹车参数:" + brake); } }