Local Player Authority
Please explain how can I use Local Player Authority on a player object in case I do not use NetworkTransform.
For example I have:
public class PlayerController : NetworkBehaviour {
void Update() {
if(hasAuthority) {
//how can i manage server player object from here?
}
}
}
Answer by iShadowfax · Dec 11, 2015 at 06:35 PM
When using UNET and instanciate an object as a Player we have 2 instances: 1) Client instance that is on client 2) Server instance that is on server
We use syncVars while setting them on server to sync them with client. We use [command] to run code on server player object and call it from client.
If client has no authority of it's object than we can only modify it from server and sync with client via syncVars.
My question is: If client has an authority on his server object how can we sync server properties from client?
Answer by quinng · Jan 03, 2016 at 06:02 PM
SyncVars will sync the properties on all instances of a network object with those of the authoritative instance.
By default the authoritative instance of a network object is the one on the server. Player objects are special in that they are local player authoritative. The local instance of the player object is the authority for its SyncVars, and it is allowed to send Commands to the server.
So to answer your question: The SyncVars on player objects should automatically sync from the local client. To sync properties from the server, You need to use a ClientRPC instead.
With the release of Unity 5.2 it is possible to assign a remote client ownership of a non-player object, so that can also send Commands to the server.