Synchronize objects when connected

Dear… whoever :slight_smile:

I’m really new to this networking stuff, just trying to find out.
I’ve got an application where you can start a server, and with a second build you can join the server. So far so good.

I now also have, when the server clicks a sphere object turns red, click again and it goes white. This is send so the client sees it as well. It’s this code:

// Update is called once per frame
	void Update () {
		if(Network.isServer) {
			if(Input.GetMouseButtonUp(0)) {
				NetworkViewID viewID = Network.AllocateViewID();
				networkView.RPC("ChangeMaterial", RPCMode.All, viewID);
			}
		}
	}
	
	[RPC]
	void ChangeMaterial(NetworkViewID viewID) {
		if(!clicked) {this.renderer.material.color = Color.red;	clicked = true;} 
		else {this.renderer.material.color = Color.white; clicked = false;}
	}

There is one problem though.
If the server has clicked once before, the sphere is red. If the client then joins, on his screen it is still white.
If the server clicks again, on the server side the sphere becomes white but on the client side it goes red. and so on.

How should I synchronize the client with the server as soon as the player joins?

Hope I was clear, thanks in advance.

RPCMode.AllBuffered or RPCMode.OthersBuffered

And that gave me an error. Now I can see the design of my application is really bad, but yeah I was going to write it again anyway.
|Thanks for the help so far, that was the problem actually, but now I’m getting an error because something isn’t attached into the game correctly :slight_smile:

But thanks!