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.
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.
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?