zak666
1
Wanting to stream a symple int EarthLifePoints to all players so earths life is the same for all players.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Earthlife : Photon.MonoBehaviour {
public static int EarthlifePoints = 100;
public Text EarthlifeTxt;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (photonView.isMine) {
//displayEarthlife
EarthlifePoints.Text = "%" + Earthlife;
}
}
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
if(stream.isWriting) {
//stream Earth Life to all players.
stream.SendNext(EarthlifePoints);
stream.SendNext(EarthlifePoints);
}
else {
//stream Earth Life to all players.
(EarthlifePoints)stream.ReceiveNext();
(EarthlifePoints)stream.ReceiveNext();
}
}
}
Change
//stream Earth Life to all players.
(EarthlifePoints)stream.ReceiveNext();
(EarthlifePoints)stream.ReceiveNext();
to
//stream Earth Life to all players.
EarthlifePoints = (int)stream.ReceiveNext();
EarthlifePoints = (int)stream.ReceiveNext();
Edit: Although after further consideration I can’t understand why you are sending and receiving the same data twice each time. I think you might want to change your function to
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
if(stream.isWriting) {
//stream Earth Life to all players.
stream.SendNext(EarthlifePoints);
}
else {
//stream Earth Life to all players.
EarthlifePoints = (int)stream.ReceiveNext();
}
}