【发布时间】:2019-10-12 11:50:44
【问题描述】:
我正在开发一款多人汽车游戏。 一切正常,主人和客户都很好地连接到房间。 (我一直在用马可波罗教程) 问题是当我看到其他汽车在屏幕上移动时,位置会通过传送汽车来更新。一直出现又消失。
我的部分代码:
PhotonNetwork.automaticallySyncScene = false;
public class CNPlayerManager : Photon.MonoBehaviour
{
...
void FixedUpdate()
{
if (photonView.isMine)
{
//it works fine
}
else
{
transform.position= Vector3.Lerp(transform.position, this.correctPosition, Time.deltaTime * 5);
transform.rotation= Quaternion.Lerp(transform.rotation, this.correctRotation, Time.deltaTime * 5);
}
}
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else
{
this.correctPosition = (Vector3)stream.ReceiveNext(); //Line 100
this.correctRotation = (Quaternion)stream.ReceiveNext(); //Line 101
}
}
我的汽车预制件中的 PhotonView 是这样的:
(来源:photonengine.com)
但在我的光子版本中,我有更多选择。在所有者中,我有“在运行时设置”和“固定”。在“观察到的组件”中,我有 2 个组件,我的汽车预制件和脚本 CNPlayerManager。
当我玩两辆车时,在第一辆车上我有时会收到这个错误:“IndexOutOfRangeException: Array index is out of range. PhotonStream.ReceiveNext ()...”在第 100 行。 在第二辆车上我得到了同样的结果。
你能帮帮我吗?
【问题讨论】:
标签: unity3d multiplayer photon