这与http://forum.unity3d.com/threads/re...ms-to-be-broken-in-5-2-1.359149/#post-2785856
中的问题相同我的问题如下:
1)将客户端权限分配给object: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
}
}
答案 0 :(得分:0)
Unity的优秀人才帮助我解决了这个问题,这是我自己的错误。
我花了至少2 - 3个月的时间来尝试修复它们立即修复。
我错过的是我在我的pos-sync-script中检查了导致问题的权限。它位于“Cmd_ProvidePositionToServer”。
以下是代码:
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class Object_SyncPosition : NetworkBehaviour {
private Transform myTransform;
[SerializeField] float lerpRate = 5;
[SyncVar] private Vector3 syncPos;
private NetworkIdentity theNetID;
private Vector3 lastPos;
private float threshold = 0.5f;
void Start () {
myTransform = GetComponent<Transform> ();
syncPos = GetComponent<Transform>().position;
}
void FixedUpdate () {
TransmitPosition ();
LerpPosition ();
}
void LerpPosition () {
if (!hasAuthority) {
myTransform.position = Vector3.Lerp (myTransform.position, syncPos, Time.deltaTime * lerpRate);
}
}
[Command]
void Cmd_ProvidePositionToServer (Vector3 pos) {
syncPos = pos;
}
[ClientCallback]
void TransmitPosition () {
if (hasAuthority && Vector3.Distance(myTransform.position, lastPos) > threshold) {
Cmd_ProvidePositionToServer (myTransform.position);
lastPos = myTransform.position;
}
}
}