问题
I've been having some issues with how other clients behave in a player's game. Basically, if there's a change that affects every client, it will work. However, it will only show up correctly on the local player's screen. Other players (as they appear on a client's screen) remain unchanged.
For example, let's say I have a boolean called "test" set to false. Every player in the room at the same time is meant to turn this boolean to true. Each player's own character gets "test" set to true, but other clients on a local player's screen show their boolean as false.
Example of how I go through every player below:
foreach (var item in PhotonNetwork.PlayerList)
{
var itemPhotonView = (PhotonView)item.TagObject;
itemPhotonView.RPC("SetPlayerTeam", item, citiString);
}
I want the code above to go through every character, even if not a local player. I believe it accomplishes it, but I'm not 100% sure.
public override void OnPlayerPropertiesUpdate(Player target, ExitGames.Client.Photon.Hashtable changedProps)
{
if (changedProps.ContainsKey("team"))
{
var targetPhotonView = (PhotonView)target.TagObject;
targetPhotonView.RPC("ChangeTeamObjs", target, changedProps);
}
}
The code above I know for sure does not change non-local clients. I'm unsure if I should use the 'foreach' method like the first example because I'm not even sure if that will accomplish it. Any ideas?
回答1:
Sending rpc to all can be done in a more efficient way, by defining the target of the rpc to be everyone, this will prevent overloading the network traffic, and only one rpc is sent.
https://doc.photonengine.com/en-us/pun/v2/gameplay/rpcsandraiseevent#targets__buffering_and_order
PhotonView photonView = PhotonView.Get(this);
photonView.RPC("ChangeTeamObjs", RpcTarget.All, , item, citiString);
Bye,
Jean
来源:https://stackoverflow.com/questions/59621728/pun-changes-affect-local-players-only-not-other-clients