- Home /
Question by
abhishek_hingorani · Mar 30, 2017 at 01:30 PM ·
unity 5networkingmultiplayermultiplayer-networkingmultiplayer networking
UNET Networking: Changing Players texture
Hello! I'm trying to make a simple Multiplayer FPS game. I want to give user the functionality to change players look. I have created different textures as well which changes the players look and color. So user can choose one of the available textures.
I store the index of the texture that user has selected as PlayerPref
and apply that texture to the player gameObject. The problem is the change of texture is only reflected on the local client and not on other clients.
Here is the script that is assigned on the Player Prefab:
void Start ()
{
if (isLocalPlayer)
{
CmdBroadCastNewPlayerSetup();
}
}
[Command]
private void CmdBroadCastNewPlayerSetup()
{
RpcSetupPlayerOnAllClients();
}
[ClientRpc]
private void RpcSetupPlayerOnAllClients()
{
int currentTexture = PlayerPrefs.GetInt("PlayerTexture", 0);
GetComponentInChildren<Renderer>().material.mainTexture = Resources.Load(currentTexture.ToString()) as Texture;
}
Thankyou for help!
Comment