Gerardo Martinez
Gerardo Martinez

Reputation: 11

How to sync a variable through Photon PUN

I need to sync a variable so all the players have the same value. I have tried with something like this

[PunRPC]
void Setting ()
{
I = somevalue;
//I Is my int
}

And I call it the following way:

PhotonView PV = GetComponent<PhotonView>();
PV.RPC("Setting", RPCTargets.All);

But the int value is null. What am I doing wrong?

Upvotes: 1

Views: 10702

Answers (1)

Trung Bui
Trung Bui

Reputation: 111

You must pass parameter on function to all client can get this parameter. Just change your code to:

[PunRPC]
void Setting (int someValue)
{
I = somevalue;
}

void CallSetting()
{
PhotonView PV = GetComponent<PhotonView>();
PV.RPC("Setting", RPCTargets.All, someValue);
}

You can pass PhotonMessageInfo additional on Setting fucntion to know more information of this client take setting call.

[PunRPC]
void Setting (int someValue,  PhotonMessageInfo info)
{
}

Upvotes: 2

Related Questions