Unet Unity islocal 播放器报错

Unet Unity islocal player error

我正在基本的 2d 游戏上测试 Unet 多人游戏功能。目前它由单个 box/racket 上下移动组成。在 monobehaviour class 中,盒子可以正确地上下移动,但是当我在 networkbehaviour class 中包含 islocalplayer 时,盒子不会上下移动。当我玩游戏时,网络信息框显示是本地号码。我该如何改变这个。

using UnityEngine;
using UnityEngine.Networking;

public class MoveRacket : NetworkBehaviour
{
  public float speed= 30;
  public string axis = "Vertical"; 

  void Update()
  {

    if (!isLocalPlayer)
    {
       return;
    }

    float v = Input.GetAxisRaw(axis);
    GetComponent<Rigidbody2D>().velocity = new Vector2(0, v) * speed;
  }

}

确定在网络管理器游戏对象>生成信息>检查自动创建玩家

isLocalPlayerNetworkObject文件中,尝试打开NetworkObject脚本,发现:

public bool IsLocalPlayer => NetworkManager.Singleton != null && IsPlayerObject && OwnerClientId == NetworkManager.Singleton.LocalClientId;

如果有,您应该将 isLocalPlayer 更改为 IsLocalPlayer