说你有
使用"新的"统一网络,你必须有(据我所知)一个NetworkManager地方.它会产生荒谬的"玩家"对象.
荒谬的"玩家"对象必须有一个继承自的类NetworkBehaviour.
大多数团队称该类为"Comms"或"AbstractPlayer"或"Junction".
public class Comms : NetworkBehaviour { }
Run Code Online (Sandbox Code Playgroud)
因此,每个命令(如"跳转")都必须由"Comms"类调解.
对于每个命令(如"Jump"),您需要 Comms类中的一对函数:
public class Comms : NetworkBehaviour {
// for every command (say, "Jump") you need THIS PAIR of functions:
public void CommandJump() {
Debug.Log("this is comms - client, do a Jump");
CmdJump();
}
[Command]
void CmdJump() {
Debug.Log("this is comms - server. a Jump arrived");
// simply pass on that command to the correct script on a server... …Run Code Online (Sandbox Code Playgroud)