我尝试了多种技术,但仍然没有结果。这篇 文章看起来很有希望,但我仍然有同样的问题。主机可以更改颜色,但不能为客户端玩家更改颜色。代码看起来像这样。
public List<GameObject> bases = new List<GameObject>();
[SyncVar]
public Texture redTexture;
[SyncVar]
public Texture blueTexture;
[SyncVar]
GameObject objID;
NetworkIdentity objNetID;
public void CheckTexture()
{
if (isLocalPlayer)
{
for (int i = 0; i < bases.Count; ++i)
{
var tempScript = bases[i].GetComponent<BaseScoreScript>();
if (tempScript.owner == "blue")
{
objID = bases[i];
CmdCheckText(objID, blueTexture);
}
}
}
}
[ClientRpc]
void RpcChangeTexture(GameObject obj, Texture text)
{
obj.GetComponentInChildren<MeshRenderer>().material.mainTexture = text;
}
[Command]
void CmdCheckText(GameObject obj, Texture texture)
{
objNetID = obj.GetComponent<NetworkIdentity>();
objNetID.AssignClientAuthority(connectionToClient);
RpcChangeTexture(obj, texture);
objNetID.RemoveClientAuthority(connectionToClient);
}
任何的意见都将会有帮助。提前致谢。