I have seen quite a bit of examples and documentation until now regarding rpc and client server however, there’s a very stupid and very obscure subject on which I hope those good amongst you can shed some light:
requesting a server variable from a client, and updating said value… when the scripts are in different gameobjects.
I have seen quite some examples of RPC calls when the script calls an rpc function on that same script on the server or .others, but what about calling an rpc function somewhere else, asking for a variable value, or trying to set up a variable there?
My attempts at making a STATIC rpc function, or even a very stupid “return server variable” rpc function have failed miserably, especially since RPC returns always VOID.
Please help, thanks.
This is basically the code that I need to use, but that doesn’t update my needed variable, when run client-side.
private int variable = 0;
void OnNetworkLoadedLevel () {
if (Network.isServer) {
print("As a server");
variable = returnvariable();
}
else {
print("As a client");
networkView.RPC("returnvariableRPC",RPCMode.Server, Network.player);
}
print (variable + " doesn't hold the value it should");
}
private int returnvariable() {
do_stuff();
}
[RPC]
public void returnvariableRPC(NetworkPlayer player) {
int localvariable = do_stuff();
networkView.RPC("assignvariableRPC",player,localvariable);
}
[RPC]
public void assignvariableRPC(int parameter) {
variable = parameter;
}