简体   繁体   English

将 Unity.Netcode 与 Starter Asset Controller(新输入系统)一起使用时,网络客户端使用了错误的输入设备

[英]Network Client use wrong input devices when using Unity.Netcode with Starter Asset Controller (New input system)

The server is always using Keyboard and Mouse just fine.服务器始终使用键盘和鼠标就好了。

The client however always use "xbox controller" instead of Keyboard & Mouse:然而,客户端总是使用“xbox 控制器”而不是键盘和鼠标:

The following is the inspector view as a client:下面是作为客户端的inspector视图:

在此处输入图像描述

The Start Asset input action are unchanged, Start Asset 输入操作不变, 在此处输入图像描述

This is what I tried but client is still being assigned to controller:这是我尝试过的,但客户端仍被分配给 controller:

private void Start()
{
    if (!IsOwner)
    {
        Destroy(GetComponent<PlayerInput>());
    }
}

How could I fix this?我该如何解决这个问题? Other than hard coding (PlayerInput)map.SwitchCurrentControlScheme("KeyboardAndMouse");除了硬编码(PlayerInput)map.SwitchCurrentControlScheme("KeyboardAndMouse"); ?

This issue is fixed by disabling Player Input script.此问题已通过禁用Player Input脚本得到解决。

And only enable it on Network Spawn.并且只在 Network Spawn 上启用它。

    public override void OnNetworkSpawn()
    {
        base.OnNetworkSpawn();
        if (IsOwner)
        {
            _playerInput = GetComponent<PlayerInput>();
            _playerInput.enabled = true;
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM