0

我是unity3d上的光子初学者。我想在游戏中同步移动角色。我将脚本作为观察者附加到光子视图并使用此代码

void OnPhotonSerializeView(PhotonStream stream,PhotonMessageInfo info)
{
    if (stream.isWriting)
    {
        Debug.Log("writing");
        stream.SendNext(transform.position);
        stream.SendNext(transform.rotation);

    }
    else
    {
        Debug.Log("reading");
        this.correctPlayerPos = (Vector3)stream.ReceiveNext();
        this.correctPlayerRot = (Quaternion)stream.ReceiveNext();
    }
}

问题是创建房间的玩家可以改变玩家的位置和旋转,它只能写。但是第二个玩家(加入房间)不能改变位置和旋转,它只能阅读。我的设置可能有什么问题。

为此,我遵循了马可波罗教程(http://doc.exitgames.com/en/pun/current/tutorials/tutorial-marco-polo)。任何帮助都非常感谢。

4

1 回答 1

0

如果您通过 PhotonNetwork.Instantiate 为每个玩家实例化一个游戏对象,那么每个客户端都有它自己的游戏对象,该客户端可以为其编写更新。

于 2014-06-23T16:17:03.550 回答