- Home /
How to send a variable to all other devices connected to a server?
Hello,
what is the best way to send variable to other devices? I am currently making a simple card game and what I just want that happens is that when a player presses end turn that a Int in all other devices is changed to the player who has the next turn. example: Player 2: played his cards (also means he ended it's turn) Player 2 script: (is it possible to do something like this) (I know how foreach works and I know this wouldn't work but this is what I want to happen) Foreach (connected device) { int PlayerTurn += 1 } not only this variable will have to change. Lists will need to change to(the player cards are in the list) or boolean will need to change.
Or is there a different way to just have a variable In common?
Answer by hexagonius · Mar 19, 2017 at 10:18 AM
you can just mark the variable you want to send/ sync with [SyncVar]
https://docs.unity3d.com/ScriptReference/Networking.SyncVarAttribute.html
Will this var will always be synced or will it be synced again evrytime you pass that line of code
Your answer
![](https://koobas.hobune.stream/wayback/20220612113507im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Animation & sound over network 1 Answer
Syncing terrain over Network 0 Answers
UNET AddPlayerForConnection with already existing player GameObject 0 Answers