Very confused. I’ve been doing networking code for a couple weeks now and aside from a few bumps, have experienced great success. Now all of a sudden something doesn’t work, and it makes no intuitive sense. I’ve gone over the code obsessively and found nothing.
Basically, on connect a player’s character spawns and its name is changed. There’s also an RPC to change the name of the gameobject for everyone else, too (so if anyone looks for Player1, they’ll find it, for instance).
Here’s the code that runs on player spawn:
GameObject mynewplayer = (GameObject)Network.Instantiate(PlayerPrefab, new Vector3(15, 30, 0), Quaternion.Euler(new Vector3(0, 180, 0)), 0);
mynewplayer.GetComponent<PlayerControl>().RenameMe("Player1");
mynewplayer.networkView.RPC("RenameMe", RPCMode.OthersBuffered, "Player1");
I can at least verify that the code is running because the second line works fine, so I have to assume it’s also running the third line that runs the RPC.
Here’s the function it’s running.
[RPC]
public void RenameMe(string newname)
{
name = newname;
}
Simple as can be. Doesn’t work, though. Simply doesn’t work. So when I connect, it makes my player’s GameObject name Player1 for me, but for nobody else.