作者只是业余时间接触Unity 2个月的新人一枚,如有不对的地方,请各位大神指正!
Unity 5.以后使用了新的网络模块UNet(其实我接触的晚压根没用过老的- -!),但是在使用过程中确实关于UNet的资料和讨论挺少的,于是自己做了个小项目测试了Command和ClientRpc两个命令。
首先我们看看官方给出的定义:
Commands
Commands are sent from player objects on the client to player objects on the server. For security, Commands can only be sent from YOUR player object, so you cannot control the objects of other players. To make a function into a command, add the [Command] custom attribute to it, and add the “Cmd” prefix. This function will now be run on the server when it is called on the client. Any arguments will automatically be passed to the server with the command.
ClientRpc Calls
ClientRpc calls are sent from objects on the server to objects on clients. They can be sent from any server object with a NetworkIdentity that has been spawned. Since the server has authority, then there no security issues with server objects being able to send these calls. To make a function into a ClientRpc call, add the [ClientRpc] custom attribute to it, and add the “Rpc” prefix. This function will now be run on clients when it is called on the server. Any arguments will

最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



