Networking Unity, I need to pass a simple variable value between Client and Server.

Help, I want to create a multiplayer game in which the player ONE can choose one of the four attacks, and when he press the button, in the device of the other player (player TWO) the gameobject of the player ONE do the animation and do damage to the player TWO. (like all Pokemon games)
How can I pass variables values between the two devices and then do something?
I found something about the SyncVar but I didn’t understand how they works and if they are what I need to do that.
Please, if you can, show me some script examples that do that.

[SyncVar] is a command that synchronizes the variable between the client and the server (but not with the rest of the clients), its written right before the variable itself,example:
[SyncVar] int example1;
that will synchronize every value change with the server.
if you want to synchronize the value between two clients then you have to synchronize the value from client one to the server and then from server to client two and you can do that by the [ClientRpc] command, example:

//this will sync the variables value from client to server
[SyncVar] int example1;

void Update ()
{
    RpcSyncVarWithClients (example1);
}

//this will sync var from server to all clients by calling the "SyncVarWithClientsRpc" funtion on the clients with the value of the variable "varToSync" equals to the value of "example1"
[ClientRpc]
void RpcSyncVarWithClients (int varToSync)
{
    example1 = varToSync;
}

note: ClientRpc functions have to start with “Rpc” like: void RpcExample ()
I hope that helped you :slight_smile:

Hamza Odeh