NetworkServer.Spawnfunction to spawn game objects with Network Identity components. Spawning them this way assigns them a
netIdand creates them on clients connected to the server.
NetworkBehaviour(instead of the default
MonoBehaviour), then you can add your script as a component to a game object.
OnStartClientfor the player game object on the local client
OnStopClientfor the player game object on the local client
hasAuthoritywill be true for such objects in client context.
OnStartClientare called on the same game object. Both these functions are useful for actions that are specific to either the client or server, such as suppressing effects on a server, or setting up client-side events.
[ServerCallback]return immediately if the client is not active. Likewise,
[ClientCallback]return immediately if the server is not active.
[Client]attributes do not generate compile time errors, but they do emit a warning log message if called in the wrong context.
ClientCallbackattributes act the same as above but do not cause a warning to be generated.
Cmdso it's easier to recognize in your calling code what will be happening.
[ClientRpc]. While not required, it is strongly suggested to prefix method names with
Rpcso it's easier to recognize in your calling code what will be happening.