Below is a fragment of my code where the Rpc and Cmd are called.
As you can see I check if the player is the client or the server, and depending on which they are I call either an Rpc or a Cmd passing the same parameter.
Debugging this script I can see that the server calls RpcSendRList
and the client calls CmdSendRList
as desired.
if(networkController.isServer)
{
networkController.RpcResetRppList();
foreach(KeyValuePair<int, float> entry in resources)
{
networkController.RpcAddToRppList(entry.Key, entry.Value);
}
}
else
{
networkController.CmdResetRppList();
foreach(KeyValuePair<int, float> entry in resources)
{
networkController.CmdAddToRppList(entry.Key, entry.Value);
}
}
Below are the Rpcs being called:
[Command]
public void CmdAddToRppList(int _key, float _value)
{
opponentResources.Add(_key, _value);
}
[ClientRpc]
public void RpcAddToRppList(int _key, float _value)
{
opponentResources.Add(_key, _value);
}
Debugging this second script only the Rpc
is actually called on the client and the Cmd
is never called on the server (the breakpoint is never hit).
What am I doing wrong with the commands?