0

I have tried multiple techniques, but still no result. The host is able to change the color, but not for the client players. The code looks like this.

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);
}
Laurel
  • 5,965
  • 14
  • 31
  • 57
CaptObvious
  • 31
  • 1
  • 5
  • http://stackoverflow.com/questions/34191207/unet-multi-player-game-having-both-players-interact-with-gameobject-changes-sy – CaptObvious Mar 21 '16 at 15:00

1 Answers1

0

Thanks for any who look at this. I solved the issue. Probably not the most efficient, I can work on that later. But I added a [Command] to the non player object (which does have a NetworkIdentidy and set to local player), in this command I reference a list of players in the scene and set a public variable in the playersscript (which is a SyncVar <- that what did it). And in the playerscript I reference that non Player object and set its texture to the one I wanted. Not worried if it isLocalPlayer or not, because I want all players to see the change.

[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;
        }
    }
}

that's the code in the non-player script and:

[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;
        }

    }
}

for the playerscrip. I know its not pretty. But yea, if you have any suggestions on better ways to do this, please let me know. And if this is helpful to someone... Awesome Sauce!

CaptObvious
  • 31
  • 1
  • 5