Unity接入飞行遥杆外设

readme

最近有朋友玩DSC,对于摇杆操控很感兴趣,然后想要接入外设来子级设计一套飞行逻辑。

设备测试

这里使用的设备是罗技X56摇杆套件、图马斯特摇杆套件

Unity使用插件

Rewired

场景搭建

创建空对象,挂载输入脚本:InputManager
接入硬件后,在右侧 Joy数组,会有遥杆名称,根据名称,展开以下的按键或者向量,即获得遥杆的操作值。

脚本测试

创建测试脚本:Control_X56
挂载到空对象,即可得到控制数值。

using Rewired;
using System;
using UnityEngine;

public class Control_X56 : MonoBehaviour
{
    
    
    InputManager inputManager;

    public Controller[] controllers;
    public Joystick joystick_1;

    public float F;

    void Start()
    {
    
    
        controllers = ReInput.controllers.GetControllers(ControllerType.Joystick);

        for (int i = 0; i < controllers.Length; i++)
        {
    
    
            //其他外设

            if (controllers[i].name == "Thrustmaster HOTAS Warthog Throttle")
            {
    
    
                joystick_1 = (Joystick)controllers[i];
                Debug.Log("油门杆已找到 - " + controllers[i].name);
            }
        }
    }

    void Update()
    {
    
    
        if (joystick_1 != null)
        {
    
    
            // 0-0.7f
            F = joystick_1.Axes[0].value;
        }
    }

}

猜你喜欢

转载自blog.csdn.net/weixin_38531633/article/details/141826591