- Home /
PHOTON/ Syncing player name and sprite to other players?
Currently I have a script attached to my player object that spawns along with other players, I've successfully achieved movement and camera follow on the players, however I need to update the sprites so players can choose their unique skin, and on top of that show their names!
// This is the script which I use for offline and for the multiplayer! I've set my skins in an array, and have an ID (skinAtual) stored in a playerprefs.int that is the position of the selected sprites. I've looked online and tryed this RPC method which causes for the player to see everyone on the game with his name and skin on all the players, and now I'm stuck and don't know how to proceed!
private void Start()
{
if (isOnline)
{
PV = GetComponent<PhotonView>();
//idSkin = PlayerPrefs.GetInt("skinAtual");
//nome = PlayerPrefs.GetString("name");
}
spr = GetComponent<SpriteRenderer>();
CarregarSkin();
}
void CarregarSkin()
{
if (isOnline)
{
if (PV.IsMine)
PV.RPC("loadSprite", RpcTarget.AllBuffered, null);
}
else
{
spr.sprite = skins[PlayerPrefs.GetInt("skinAtual")];
}
}
[PunRPC]
void loadSprite()
{
GetComponent<SpriteRenderer>().sprite = skins[PlayerPrefs.GetInt("skinAtual")];
txtNome.text = PlayerPrefs.GetString("name");
}
This is what I get inGame:
Your answer
Follow this Question
Related Questions
Unity Photon Transform Issues 0 Answers
How to use photons SetSynchronizedValues() 0 Answers
Photon position syncing 0 Answers
Photon Networking - What function(s) are called when a player (not me) is spawned? 2 Answers
PUN - Unity 2D Synchroniztion 0 Answers