【问题标题】:Trying to send RPC with PunRPC (Unity and Photon) but getting error "Object reference not set to an instance of an object"尝试使用 PunRPC(Unity 和 Photon)发送 RPC,但出现错误“对象引用未设置为对象实例”
【发布时间】:2019-07-08 07:15:00
【问题描述】:

我正在尝试在客户端将所有人发送到角色选择场景之前需要一定数量的玩家。

在一个函数中我有......

if (PhotonNetwork.PlayerList.Length == 1 & PhotonNetwork.IsMasterClient == true)
{
    PhotonView PV = PhotonView.Get(this);
    PV.RPC("heroSelect", RpcTarget.All);
}

在我的代码中,我用...更改场景

[PunRPC]
void heroSelect()
{
    SceneManager.LoadScene(2);
}

我收到“对象引用未设置为对象的实例”作为该行的错误

PV.RPC("heroSelect", RpcTarget.All);

【问题讨论】:

    标签: c# unity3d rpc photon


    【解决方案1】:

    我发现了问题所在。

    在您的层次结构中创建一个空。我打电话给我的 NetworkManager。将您的脚本添加为组件。 (您可能已经完成了这两个步骤。)

    重要的是这一点。 确保您的 NetworkManager 上有 Photon View。将 NetworkManager 从层次结构拖到检查器中的 Observed Components 上。这应该可以修复错误。

    【讨论】:

      猜你喜欢
      • 2014-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-12
      • 2015-07-23
      • 2011-07-09
      • 2012-08-31
      • 2011-11-21
      相关资源
      最近更新 更多