Issue modifying variables with an RPC.
I am calling an RPC with an integer parameter and I can see that I am successfully receiving it. However, when I try to set a variable within the RPC, it seems to not be working as I expect.
I this example, the rpc is called with 2 as the integer being passed.
int num = 1;
void Update()
{
Debug.Log("The number is: " + num); // Always says "The number is: 1"
}
[RPC]
void TestRPC(int x)
{
Debug.Log ("x: " + x); // "x: 2" as expected
num = x;
Debug.Log ("num: " + num); //"num: 2" as expected
}
Everything looks fine with the log messages within the TestRPC method, but in Update num is not changed to 2 but is always 1.
I this example, the rpc is called with 2 as the integer being passed.
int num = 1;
void Update()
{
Debug.Log("The number is: " + num); // Always says "The number is: 1"
}
[RPC]
void TestRPC(int x)
{
Debug.Log ("x: " + x); // "x: 2" as expected
num = x;
Debug.Log ("num: " + num); //"num: 2" as expected
}
Everything looks fine with the log messages within the TestRPC method, but in Update num is not changed to 2 but is always 1.
0
Comments
tro to change your int num = 1; to int numtest = 1;
If an another script try to access at your int num, you will get an error.