这与http://forum.unity3d.com/threads/re...ms-to-be-broken-in-5-2-1.359149/#post-2785856中的问题相同
我的问题如下:
1) 为对象分配客户端权限:AssignClientAuthority
2)移动对象,有效
3)应用 RemoveClientAuthority 并且对象在客户端恢复到原始位置。“TEST”调用只是为了查看它是否适用于最后一个对象。
这是一个错误还是我做错了什么?
这是我做的一个测试的代码示例:
foreach (string tagName in MP_Singleton.Instance.master_Object_List) {
temp_GameObject = GameObject.FindWithTag(tagName);
Cmd_LocalAuthority (true, temp_GameObject);
temp_GameObject.GetComponent<Renderer>().sortingOrder = z;
randomX = UnityEngine.Random.Range (-0.055f, 0.055f);
randomY = UnityEngine.Random.Range (-0.055f, 0.055f);
randomX = randomX + deckStartPosX;
randomY = randomY + deckStartPosY;
Rpc_Position (temp_GameObject, randomX, randomY, z, twistAngle);
// Add to depth
z++;
}
Cmd_LocalAuthority (false, temp_GameObject); //<< TEST
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);
}
Cmd_LocalAuthority:
[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
}
}