Why do color changes of object occur on server but not on the client?

I have two players using the same prefab. I spawn in a sphere (non-player object) using this code:
sphere = Instantiate(sphereprefab, transform.position, Quaternion.identity) as GameObject;
NetworkServer.Spawn(sphere);

I have this code attached to the sphere (Script name is SphereProperties):
[SyncVar(hook = “UpdateSphereColor”)]
Color spherecolor;

public void UpdateSphereColor(Color spherecolor)
{
GetComponent().material.color = spherecolor;
}

Now when I move either player object through the sphere using the “IsTriggerEnter” method, I want to change the sphere to the color of that player and I want each player to see that color. However, it doesn’t matter which player moves through the sphere, only the server player see’s the color change. Below is the code that is attached to each player and right now I just pass in to Color.red just for testing purposes.

void OnTriggerEnter(Collider col)
{

if(col.tag == “sphereflag”)
{
GameObject.FindGameObjectWithTag(“sphereflag”).GetComponent ().UpdateSphereColor(Color.red);
}
}

I thought syncvars send any changes from the server to the clients?

You are changing colors on server and client. Secondly, you are never applying the Hook value to your syncvar.

Hi, but the color isn’t changing on the client and only on the server. How do I apply the color change to the client as well?

Also, I thought by calling the syncvar function with a color from each player I was applying the Hook value?

No. I honestly don’t see the point in a syncvar for your case. I think changing the color in the OnTrigger is prolly easier. And if you need server only simulation. Command & RPC will probably do the trick.

So in my OnTriggerEnter method (scripted attached to my player) , why doesn’t this code work?

void OnTriggerEnter(Collider col)
{

if(col.tag == “sphereflag”)
{
GameObject.FindGameObjectWithTag(“sphereflag”).GetComponent().UpdateSphereColor(Color.red);
}
}

I thought the client calls the spheres syncvar hook method passing the color red. Then the method runs and changes the color of the sphere for all the clients to see.

How would I use Command and RPC inside the OnTriggerEnter?

I don’t know why it doesn’t work. Debug it, Check if it’s being invoked everywhere etc.

And to your second question. http://lmgtfy.com/?q=Unet+command+rpc