此代码位于播放器上,对菜单中的按钮按下作出反应,其想法是当第一次按下按钮“btn_MenuKill”时它变为橙色,下次将颜色更改回原始黄色并执行“打印( "FIRE THE PROCESS")",在 SyncVar Hook "void ProcessKillObject(bool _MP_Orange) {" 中。
这是情况/问题:
在编辑器中启动主机
1)单击主机客户端(编辑器)上的按钮= [命令]有效
2)单击远程客户端上的按钮=不起作用,不要关闭[命令]
在生成的“远程”客户端中启动主机
1)单击主机客户端上的按钮= [命令]有效
2)单击远程客户端上的按钮= [命令]有效
我不明白为什么当主机在编辑器上并且我使用遥控器上的按钮时 [Command] 不起作用。
这是代码:
[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
}
}