命令未从客户端触发

Command not trigger from client

此代码位于播放器上,对菜单中的按钮按下做出反应,其想法是当按下按钮时 "btn_MenuKill" 第一次变为橙色,下一次颜色变回原始黄色并在 SyncVar Hook "void ProcessKillObject(bool _MP_Orange) {".

中执行 "print ("FIRE THE PROCESS")"

这里是 situation/problem:

在编辑器中启动主机

1) 单击主机-客户端(编辑器)上的按钮 = [命令] 有效

2) 单击远程客户端上的按钮 = 不起作用,不要触发 [Command]

在生成的 "remote" 客户端中启动主机

1) 单击主机客户端上的按钮 = [命令] 有效

2) 单击远程客户端上的按钮 = [命令] 有效

我不明白为什么当主机在编辑器上并且我使用遥控器上的按钮时[命令]不起作用。

代码如下:

[SyncVar(hook = "ProcessKillObject")] public bool MP_KillOrange = false;
[SyncVar(hook = "MoveMainMenu")] public bool MP_MainMenu;
private NetworkIdentity objNetId;
private Color32 yellowButtonColor = new Color32 (200, 200, 2, 255);
private Color32 orangeButtonColor = new Color32 (255, 96, 0, 255);

public void Btn_Kill() {

    if (!isLocalPlayer)
        return;

    foreach (string objectTag in MP_Singleton.Instance.master_Object_List) {
        GameObject dummy = GameObject.Find (objectTag);
        Cmd_LocalAuthority (true, dummy);
    }

    Cmd_ProcessKill ();
}

// SyncVar Hook
void ProcessKillObject(bool _MP_Orange) {

    if (_MP_Orange) {
        GameObject.Find ("btn_MenuKill").GetComponent<Button> ().image.color = orangeButtonColor;
    } else if (!_MP_Orange) {
        GameObject.Find ("btn_MenuKill").GetComponent<Button> ().image.color = yellowButtonColor;

        print ("FIRE THE PROCESS");
    }
}

[Command] //>>>>>> THIS IS NOT TRIGGERED
void Cmd_ProcessKill() {

    // >>>>>>>>>>>>>>>>>>>>>>
    GameObject.Find ("MyText").GetComponent<Text> ().text = "HIT"; // TO SEE THAT THE COMMAD TRIGGER
    //>>>>>>>>>>>>>>>>>>>>>>>
    if (MP_KillOrange) 
        MP_MainMenu = !MP_MainMenu;

    MP_KillOrange = !MP_KillOrange;

}


[Command]
void Cmd_LocalAuthority(bool getAuthority, GameObject obj) {

    objNetId = obj.GetComponent<NetworkIdentity> ();        // get the object's network ID

    if (getAuthority) {
        objNetId.AssignClientAuthority (connectionToClient);    // assign authority to the player
    } else {
        objNetId.RemoveClientAuthority (connectionToClient);    // remove the authority from the player
    }
}

我添加了 RPC,然后就可以了。

[ClientRpc]
void Rpc_Position(GameObject myGO, float ranX, float ranY, int zDepth, float twist) {

    myGO.transform.position = new Vector3 (ranX, ranY, zDepth);
    myGO.transform.localEulerAngles = new Vector3(0f, 0f, twist);

}