Scripting 为客户端更改子对象的纹理

Scripting 为客户端更改子对象的纹理,scripting,multiplayer,unity3d-unet,Scripting,Multiplayer,Unity3d Unet,我尝试了多种技术,但仍然没有结果。这 看起来很有希望,但我仍然有同样的问题。主机可以更改颜色,但客户端玩家无法更改。代码如下所示 public List<GameObject> bases = new List<GameObject>(); [SyncVar] public Texture redTexture; [SyncVar] public Texture blueTexture; [SyncVar] GameObject objID; NetworkIdentit

我尝试了多种技术,但仍然没有结果。这 看起来很有希望,但我仍然有同样的问题。主机可以更改颜色,但客户端玩家无法更改。代码如下所示

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);
}
public List base=new List();
[同步变量]
公共纹理;
[同步变量]
公共纹理;
[同步变量]
游戏对象对象对象;
网络标识objNetID;
公共void CheckTexture()
{
if(IsLocalLayer)
{
对于(int i=0;i
任何建议都会有帮助。
提前感谢。

感谢所有看过这篇文章的人。我解决了这个问题。可能不是最有效的,我可以稍后再做。但是我在非玩家对象中添加了一个[Command],该对象有一个NetworkIdentity并设置为local player,在这个命令中,我引用了场景中的玩家列表,并在PlayerScript中设置了一个公共变量(这是一个SyncVar)
[Command]
void CmdSyncOwner(string own)
{
    //List<GameObject> players = new List<GameObject>();
    foreach (GameObject obj in GameObject.FindObjectsOfType<GameObject>())
    {
        players.Remove(obj);
        players.Add(obj);
    }

    for (int i = 0; i < players.Count; ++i)
    {
        if (players[i].tag.Contains("Ply"))
        {
            players[i].GetComponent<FPSPlayerFunction>().baseOwner = own;
        }
    }
}
[SyncVar]
public string baseOwner;

void BaseStatus()
{
    var blue = Color.blue;
    var red = Color.red;

    foreach(GameObject obj in bases)
    {
        if (baseOwner == "blue")
        {
            centBaseStatus.image.color = blue;
            centBaseStatus.GetComponentInChildren<Text>().text = "Center Base : "+ baseOwner;
            GameObject.Find("CenterBase").GetComponentInChildren<Renderer>().material.mainTexture = BlueBase;
        }

    }
}