Change the player's color over the network
Hi, i am creating a game where the player can choose to be in the blue team or the red team, so I have a button "RedTeam" and a button "BlueTeam" who will affect the variable "myTeam" of the player who pressed the button, this is working but i can't seem to figure out how to change the renderer of the player to assign the color of his team over the network, it only works locally. Here is the piece of code of my script:
public void SetColor()
{
if (isLocalPlayer == true) {
CmdPlayerColors ();
}
}
[Command]
void CmdPlayerColors()
{
if(myTeam == "Blue"){
rend.material.SetColor("_Color", Color.blue);
//Debug.Log (transform.name + " is blue");
}
if(myTeam == "Red"){
rend.material.SetColor("_Color", Color.red);
//Debug.Log(transform.name +" is red");
}
}
Thanks in advance.
Answer by pKallv · Dec 10, 2016 at 07:24 PM
@antiNT: You need RPC, here is how i do it. See if you can modify that.
CmdPaint (aGO, Color.yellow);
Executed this:
[Command]
void CmdPaint(GameObject obj, Color col) {
objNetId = obj.GetComponent<NetworkIdentity> (); // get the object's network ID
RpcPaint (obj, col);
}
[ClientRpc]
void RpcPaint(GameObject obj, Color col){
obj.GetComponent<Renderer>().material.color = col; // this is the line that actually makes the change in color happen
}
Ok, so I used your method and only the client can change it's color, the server will always be white (the default color)... Any ideas?
Your answer
Follow this Question
Related Questions
[Problem] Change 3DText color with C# script 1 Answer
Black unity theme? 2 Answers
How to resize the terrain (canvas) without resizing the existing hills? 0 Answers
How do I turn "Surface Shader" on? 0 Answers
Unity Network Connection Problem. 0 Answers