# Unity5 multiplayer healthtag update issues

I followed some tutorials about unitys UNET. I have setup a offline and online scene and can spawn player prefabs. I use "Command" and "ClientRpc" calls to update and sync some variables. For example if i press "c" on my keyboard i change my color randomly and tell it to the server using "Command", that command calls the "ClientRpc" which set the color in the other instances as usual. It looks like

if(Input.GetKeyDown("c")) CmdChangeColor(Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f));

[Command]
void CmdChangeColor(Color c) {
GetComponent<Renderer>().material.color = c;
RpcChangeColor(c);
}

[ClientRpc]
void RpcChangeColor(Color c) {
GetComponent<Renderer>().material.color = c;
}


But now i will add a tag that will fly over me using the same procedure with some additions. The variable tag has the "SyncVar" attribute.

if(Input.GetKeyDown("t")) CmdSetTag(Random.Range(0,100));

[Command]
void CmdSetHealth(int value) {
tag = value;
RpcSetTag(value);
}

[ClientRpc]
void RpcSetTag(int value) {
tag = value;
}


Then in the Update() function i call

GameObject.Find("MyTag").GetComponent<TextMesh>().text = tag.ToString();


I also tried to exclude the local player but it doesnt work like it does with the color. It seems there is some confusiness in the scene between the tags because it seems i always change the host players tag and not my own. I ran into that issue with the first person camera, where i had multiple rendered cameras in the scene because i added a camera onto every prefab, but in this case the NPC player do need the tag so i dont know whats my problem here and hope for some hints/solutions

Thank you

• Why did you use the SyncVar attributed (which automatically synchronizes the value of a variable) if you wanted to set it manually with commands/RPCs? – DMGregory Apr 19 '19 at 12:21