Question by
Fred_Vicentin · Nov 16, 2015 at 09:07 PM ·
networkingphoton
My Photon Variable is only owned from MasterClient
I done a script that when the player click on a cube, it counts i++ for that, My idea is that it count how much clicks each players done. But when I click on the scene it just i++ the masterclient variable, it update for all clients but if other client click nothing happens, but if masterclient click all the client variables change.
Here is my script:
using UnityEngine;
using System.Collections;
public class ClickToCount : MonoBehaviour
{
int clicks;
int todosClicks;
public PhotonView photonView1;
PhotonPlayer player;
public void Awake()
{
PhotonNetwork.automaticallySyncScene = true;
}
[PunRPC]
void OnMouseDown()
{
if (transform.gameObject.tag == "Player")
{
clicks++;
}
}
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
stream.SendNext(clicks);
}
else
{
clicks = (int)stream.ReceiveNext();
}
}
void OnGUI()
{
foreach (PhotonPlayer bucetao in PhotonNetwork.playerList)
{
GUILayout.Box(bucetao.name + ":" + clicks);
}
}
}
Comment
Anyone can help me ? It's looks like the community don't like too much to answer this type of questions on answer.
Your answer
![](https://koobas.hobune.stream/wayback/20220612045314im_/https://answers.unity.com/themes/thub/images/avi.jpg)