Unity Mirror - Attributes
Unity Mirror - Attributes
Network attributes are added to member functions of Network Behaviour scripts, allowing these functions to run on the client or server. These attributes can be used for implemented methods as well as Unity game loop methods like Start or Update.
[Server]
This method can only be called by the server (generates a warning if called on the client).
[ServerCallback]
Works the same as the Server attribute, but does not generate a warning if called on the client.
[Client]
This method can only be called by the client (generates a warning if called on the server).
[ClientCallback]
Works the same as the Client attribute, but does not generate a warning if called on the server.
[Command]
Use this method to execute on the server from a client. Be sure to use it for input validation, etc. If you want to call this method from the server, use it as a wrapper around another function.
[ClientRpc]
The server uses Remote Procedure Call (RPC) to run this function on clients. Also
[TargetRpc]
This is an attribute added to methods of Network Behaviour classes and allows them to be called from the server to clients. Compared to the ClientRpc attribute, these functions are called on a target client only, not on all ready clients.
[SyncVar]
SyncVars are used to automatically synchronize variables from the server to all clients. Do not assign them from a client, it will be meaningless. Do not allow them to be null, you will get errors. You can use int, long, float, string, Vector3, etc. (all plain types), and you can use Network Identity and game object, but a Network Identity must be added to the game object. You can run code when a client receives updates from the server by using SyncVar Hooks.


Yorum Gönder