material color change in RPC function not responding

An object is supposed to change its color when clicked in game. The debug shows the click is detected by OnMouseDown and the function SetColor is successfully called. But the material isnt changing in either client or server view. Debugging newColor in the SetColor function also shows it has been passed correctly. Can’t figure this out:

#pragma strict

var newCol : Vector3 = Vector3(0,0,1);

function OnMouseDown () {
	Debug.Log("Clicked");
	networkView.RPC("SetColor", RPCMode.AllBuffered , newCol);
}

@RPC
function SetColor (newColor : Vector3) {
	renderer.material.color = Color(newColor.x,newColor.y,newColor.z,1);
	Debug.Log("Set Color is called");

So, not really an RPC problem? (since it doesn't change even your own color.) Maybe double-check it works as a non-RPC. Try printing newColor in SetColor. It is using the wrong renderer (not cow1.renderer... ?) Try with the script on a simple cube.

–

1 Answer

1

I caught a glimpse of some flickering when I switched to scene view. I dont work in scene view b/c the whole thing is instantiated so I never saw it. My script was double instantiating the objects so they were all z-fighting with each other. When they arent stacked on top of each other, the colors show as they should.