2016-09-11 57 views
0

位於播放器上的此代碼對菜單中的按鈕按下作出反應,並且想法是在第一次變爲橙色時按下「btn_MenuKill」按鈕並且下一次它將顏色改回時原來的黃色和做「打印(」火過程「)」,在SyncVar掛鉤「void ProcessKillObject(布爾_MP_Orange){」。命令不從客戶端觸發

這裏的情況/問題:在編輯器中

啓動主機

1)點擊主機 - 客戶機(編輯按鈕)= [命令]工作

2)點擊按鈕remote-client =不起作用,不關火[命令]

在生成的「遠程」客戶端啓動主機

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 
    } 
} 
+0

如果我刪除「Cmd_LocalAuthority(true,dummy);」它可以工作,但是我移動的非玩家對象不會留在我移動它的位置。 – PeterK

+0

解決了,我用RPC,然後它工作。 – PeterK

回答

0

我添加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); 

}