I\'m working on and learning some basics of Unity 5, UNET, and networking. I made a simple 3D game where you go around and change the colors of objects. But I want to make i
Unity 5.3.2p3 Assign Client Authority to Non Player Objects
For anyone interested in setting this up this is my approach
Client Side OnLocalPlayer component -> Call commands to assign and remove object authority by passing through the objects NetworkInstanceId. You can add any UI to call these methods on this component
Server Side
[Command]
void CmdAssignObjectAuthority(NetworkInstanceId netInstanceId)
{
// Assign authority of this objects network instance id to the client
NetworkServer.objects[netInstanceId].AssignClientAuthority(connectionToClient);
}
[Command]
void CmdRemoveObjectAuthority(NetworkInstanceId netInstanceId)
{
// Removes the authority of this object network instance id to the client
NetworkServer.objects[netInstanceId].RemoveClientAuthority(connectionToClient);
}
Client Side
3. Object component ->
OnStartAuthority() - allowed to send commands to server
OnStopAuthority() - not allowed to send commands to server
That's all there is to it!