- Home /
How does the synchronization work with Photon Pun RPCs and stream.IsWriting?
Hey guys,
the last days I tried to understand how does the synchronization with RPCs und stream.IsWriting in Photon work. I reduced my aims more and more but the synchronization doesn't work. Could someone tell me what I'm doing wrong? Or could someone post an example of how I synchronize something simple like the position of a cube? Thank you very much!
This is my last unsuccessful try. The Script is assigned to the observed components of the Photon View of the Cube:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class CubeTest : MonoBehaviour, IPunObservable
{
PhotonView photonView;
public float x;
public float y;
public float z;
private void Awake()
{
photonView = GetComponent<PhotonView>();
}
public void Update()
{
x = transform.position.x;
y = transform.position.y;
z = transform.position.z;
}
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.IsWriting)
{
stream.SendNext(x);
stream.SendNext(y);
stream.SendNext(z);
}
else
{
x = (float)stream.ReceiveNext();
y = (float)stream.ReceiveNext();
z = (float)stream.ReceiveNext();
}
}
}
Your answer
Follow this Question
Related Questions
What's the best method to implement multiplayer on a Billiard game ? 1 Answer
how to synchronize other player actions in multiplayer environment using photon multiplayer ? 3 Answers
Photon - RPC Does Trigger but Does not Show Over Network :( 0 Answers
hi i need help with code 1 Answer
Photon enable/disable objects for 1 player but shows for all player views 0 Answers