Question by
The-Game-Master · Oct 22, 2018 at 08:18 PM ·
gameobjectnetworkingclientclient-servercommand
Networking functions work fine on player object, but not other objects
So I have the following snippet of code:
[Command]
public void CmdSetTeam(int i)
{
Debug.Log("CmdSetTeam i = " + i);
team = teams[i];
teamNum = i;
Debug.Log("team: " + team + "; teamNum: " + teamNum + "; GameObject: " + gameObject);
RpcSetTeam();
}
[ClientRpc]
public void RpcSetTeam()
{
Debug.Log("RpcSetTeam");
if (changeBodyColor)
{
Renderer r = GetComponent<Renderer>();
Material temp = new Material(r.material);
if (!team.Equals("None"))
{
if (team.Equals("Red"))
{
temp.color = Color.red;
}
else if (team.Equals("Blue"))
{
temp.color = Color.blue;
}
else if (team.Equals("Green"))
{
temp.color = Color.green;
}
else if (team.Equals("Magenta"))
{
temp.color = Color.magenta;
}
else if (team.Equals("Yellow"))
{
temp.color = Color.yellow;
}
r.material = temp; //Set the player's color to their team color
}
}
}
}
It works flawlessly on the player's object. This is all being run on the server, and I know that the functions should work because like I said it works on player objects. However, when using this script on bots, the furthest the output gets is "CmdSetTeam i = 1" or whatever i is. My question is, why is this happening? Clearly the CmdSetTeam function is called, and there's no reason it should be halting, so what's going on here? Very confused as to why it doesn't work properly. Thanks for any help.
Comment