share one of my player materials colour via networkView.RPC

Hey Folks,

I ran into someproblems sharing the material colour via network. This is the code I’m using to change the colour for my character:

The script is attached to the player object.

var redValue : float = 0.5;
var greenValue : float = 0.5;
var blueValue : float = 0.5;
var playerAppearence : GameObject; // The skinned mesh of my player that has 2 materials. "trousers" is the one I like to change the colour from. This game Object is also Nested in the player object.
var trousers : material

function Start(){
		var newColour : Vector3 = Vector3(redValue,blueValue,greenValue);
		networkView.RPC("myColour",RPCMode.AllBuffered, newColour);
}

function Update(){
}
@RPC
function myColour(myPlayerColor : Vector3){
		if(networkView.isMine){
			playerAppearence.gameObject.GetComponent(Renderer).materials[trousers].color = Color(myPlayerColor.x,myPlayerColor.y,myPlayerColor.z,1);
		}
	}

The error I get is: InvalidCastException: Cannot cast from source type to destination type.

Furthermore ALL other players either on the client or on the server have the same colour instead of only sending their own colour to every other player :frowning:

Can you help me tackle the issue ?
Help is much appreciated!

Dawnreaver

The cast exception will tell you the line where it fails. Look up that line and if you don’t get what’s the issue, post an update here.

It’s Line 75 without any further explanation than the cast exception.

well… what’s on line 75? :slight_smile:

Basically the same as this:

playerAppearence.gameObject.GetComponent(Renderer).materials[trousers].color = Color(myPlayerColor.x,myPlayerColor.y,myPlayerColor.z,1);

with the exception that the colour values change because it is not inside the RPC Function:

playerAppearence.gameObject.GetComponent(Renderer).materials[trousers].color = Color(redValue.x,greenValue.y,blueValue.z,1);

Ok Guys I solved the issue:Happy Days!

Now the line of code that switches the colour in the Awake Funktion and the RPC call is:

playerAppearence.renderer.materials[1].color = Color(newColour.x,newColour.y,newColour.z,1);

I don’t know why it works I basically played around with the code … a lot! So if anyone would like to elaborate on this for the greater community I would be very greatful.

Thanks for the help!

I am facing same problem. i want to make a video conference using webcam i can capture my video through webcam but when i want to send this video
to client through network i am not able to do it .i am sending it through RPC but i was not able to make it can any u help me please.and also how to
make live stream of it. can u please post the code.

@santosh
I have the exact same problem.! Did you get somewhere with yours?