Networking best practices for handling local player
A bit of a text wall incoming, if you read it though, thank you :)
So i am new at networking but im starting to get the gist of the client/server relationship. I am running into a bit of a problem though. When the player is spawned, the scripts which do not belong to the localPlayer are disabled. This becomes a problem when i tell the server to update a variable on all clients because that object's variable is in the script which has been disabled. Im so confused lol..
My simple project is a test to make sure my understanding of the networking is correct and so far its proving i dont fully understand it yet. In Unity i have set-up a project which has networking. I load up two instances of the game, one is the server and client, the other is just a client. When each 'Player' is created on the server, a script 'MyChat' is disabled if that player is not the local player. This is so that the OnGUI and input are only detected for the localPlayer on the clients.
When the clients/server are loaded up etc, in the MyChat script it listens for the input of 'Space'. When space is pressed then the [SyncVar] int num = 0; increases by 1. This is done by calling a Command which in turn calls a ClientRPC which tells the num to increase by one. In theory (this is the way im thinking it works) this should tell all clients on the server to increase their num varible and OnGUI it to the screen. What it does though is increase the variable num but only for the local client. If i switch to the server/client window and press space, the num increases for only that client, the same is true when i click on the other client window and press space.
The variable is only being incremented on that single client. If someone could shed some light on where my understanding of networking is failing, please do let me know, thankyou.
Your answer
Follow this Question
Related Questions
Client Spawning Player Objects 0 Answers
LAN Auto find server/host 0 Answers
Client can't answer to Server, Command methods don't work, ClientRPC do 0 Answers
Can't sync previous connected clients' color. 0 Answers
How to make a smooth transition between two servers ? (UNET, NetworkManager) 0 Answers