这是我的问题,当我以客户端身份运行此代码时,
{
if (isServer)
{
Debug.Log("je suis le serveur");
RpcAllowTeleportation();
}
else
{
Debug.Log("Je suis le client");
CmdAllowTeleportations();
}
}
[Command]
public void CmdAllowTeleportations()
{
Debug.Log("C'est passé par la fonction CmdAllowTeleportation");
if (!isLocalPlayer) { Teleportation.GetComponent<Teleport>().enabled = false; Debug.Log("cmd : it hasn't the authority"); }
else { Debug.Log("cmd : It has the authority"); }
}
[ClientRpc]
void RpcAllowTeleportation()
{
Debug.Log("C'est passé par la fonction RpcAllowTeleportation");
if (!hasAuthority) { Teleportation.GetComponent<Teleport>().enabled = false; Debug.Log("rpc : it hasn't the authority"); }
else { Debug.Log("rpc : It has the authority"); }
} ##
我有这些日志:
我的日志与代码完全不一致!您能帮我吗?
谢谢
因为它在Start
中被称为被服务器,所以它调用了
RpcAllowTeleportation();
因此在所有客户端上(因此您)RpcAllowTeleportation
被执行。
反之亦然,作为客户端,您永远不会看到来自CmdAllowTeleportations
的日志,因为它是仅在服务器上执行的[Command]
&rightarrow;。服务器将看到CmdAllowTeleportations
的日志。