C# Can';t从客户端执行服务器命令
当玩家击中屏幕时,我正试图制造一颗子弹。当我在matchmaking中创建服务器时,我可以生成项目符号,并且我也可以在客户端看到它们。但当我在配对时像客户机一样连接到服务器时,我无法产生子弹。我在服务器端遇到此错误: 在Player(Clone)>(UnityEngine.GameObject)上未发现传入的[Command:InvokeCmdCmd_Fire]行为,服务器和客户端应具有相同的NetworkBehavior实例[netId=2]。C# Can';t从客户端执行服务器命令,c#,unity3d,unity5,C#,Unity3d,Unity5,当玩家击中屏幕时,我正试图制造一颗子弹。当我在matchmaking中创建服务器时,我可以生成项目符号,并且我也可以在客户端看到它们。但当我在配对时像客户机一样连接到服务器时,我无法产生子弹。我在服务器端遇到此错误: 在Player(Clone)>(UnityEngine.GameObject)上未发现传入的[Command:InvokeCmdCmd_Fire]行为,服务器和客户端应具有相同的NetworkBehavior实例[netId=2]。 UnityEngine.Networking.N
UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate() 我的代码:
for (int x = 0; x < Input.touchCount; x++)
{
touchpos = Camera.main.ScreenToWorldPoint(touch[x].position);
if ((touchpos.x > -4.5f || touchpos.y > -1.2f))
{
pos = transform.position;
if (magazine > 0)
{
if (time > firetime && autoriffle)
{
Cmd_Fire();
time = 0;
magazine--;
}
time += Time.deltaTime;
}
[Command]
void Cmd_Fire()
{
GameObject bullet = Instantiate(bulet, pos, Quaternion.FromToRotation(Vector3.up, new Vector3(touchpos.x, touchpos.y, transform.position.z) - transform.position)) as GameObject;
bullet.GetComponent<Rigidbody>().AddForce(bullet.transform.up * bulletspeed, ForceMode.Impulse);
NetworkServer.Spawn(bullet);
// I try NetworkServer.SpawnWithClientAuthority(bullet, connectionToClient); too but same reason
}
for(int x=0;x-4.5f | |触摸位置y>-1.2f))
{
pos=变换位置;
如果(刀库>0)
{
如果(时间>点火时间和自动点火)
{
Cmd_Fire();
时间=0;
杂志——;
}
time+=time.deltaTime;
}
[命令]
void Cmd_Fire()
{
GameObject bullet=实例化(bulet,pos,四元数FromToRotation(Vector3.up,new Vector3(touchpos.x,touchpos.y,transform.position.z)-transform.position))作为GameObject;
bullet.GetComponent().AddForce(bullet.transform.up*bulletspeed、ForceMode.Pulse);
NetworkServer.Spawn(项目符号);
//我也尝试NetworkServer.SpawnWithClientAuthority(bullet,ConnectionClient);但原因相同
}
我的播放器预置上有这个脚本。我有附加播放器和子弹预置网络标识和网络转换。在播放器上我检查了本地播放器权限
我还试着做一个新项目,我把官方的Unity多人网络教程中的所有内容都放进去了,但也没有成功
谢谢你的帮助。我找到了答案。如果这个脚本没有连接到本地玩家,我就要销毁它。我应该只做-
if(!isLocalPlayer)
return;`
不是
if(!isLocalPlayer)
{
Destroy(this);
return;
}