罗技LG29在unity中的所有按键获取(包括换挡 brake档把 脚踏板油门刹车)

using UnityEngine;

using System.Collections;

using UnityStandardAssets.CrossPlatformInput;

/// <summary>
/// 首先导入 Logitech SDK 
/// 方法二需要用到sdk
/// </summary>
public class LGTest : 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("Throttle");
        Debug.Log("油门参数" + throttle);  
        
        //刹车
        float brake = Input.GetAxisRaw("Brake");
        Debug.Log("刹车参数:" + brake);
    }
}
油门的获取

刹车

   

离合器的获取



这个博客会有帮助:点击打开链接

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值