首页 > 解决方案 > Input.GetAxis("Mouse X") 不适用于某些 Windows 配置

问题描述

public float GetAxis() 
{
    if (inputDevice == InputDevice.MouseKeyboard)
    {
        return Input.GetAxis(this.buttonName);
    }
}

此代码在我的 Windows 7 x64 PC 上运行良好。我的项目输入设置是序数:

输入设置:

在此处输入图像描述

但我在 youtube 上观看了一些人们玩我的游戏的视频。他们不能在里面使用鼠标。看起来Input.GetAxis("Mouse X")Input.GetAxis("Mouse Y")没有为它们返回正确的值,并且它们无法控制游戏中的相机。

其他输入对他们来说效果很好。我的 Unity 版本是5.6.0f3,我无法升级到实际版本,因为游戏的代码太复杂了。

如何进行故障排除和修复?我还没有为其他平台构建,然后是 windows x86 和 x64。

输入对象被构造:

public GenericInput rotateCameraXInput = new GenericInput("Mouse X", "RightAnalogHorizontal");

要读取增量鼠标移动,我在 LateUpdate() 中运行此方法:

protected virtual void CameraInput()
{
    if (tpCamera == null || cc.lockCamera)
    return;
    var Y = rotateCameraYInput.GetAxis();
    var X = rotateCameraXInput.GetAxis();
}

标签: windowsunity3d

解决方案


I've come across this issue myself while using an RDP session or some kind of remote viewer such as TeamViewer. Mouse X and Mouse Y read the output directly from a device. If the device is not directly plugged into the machine that the player is being ran on then the inputs will not be properly retrieved. I'm not sure if this is the case for you, but this is the only instance I can think of these not being picked up.

Maybe you should add a bit of code that gets the mouse position each frame and outputs the difference, this would bypass the Mouse X/Y inputs anyways.


推荐阅读