Quantcast
Channel: Photon Unity Networking (PUN) — Photon Engine
Viewing all articles
Browse latest Browse all 8947

How to create a custom skin for each player

$
0
0
Hi, I am new to Photon. I have a playerPrefab which is simply a game object with some scripts (but no skin).
I want to instantiate the player on all clients and then set the correct skin which is either a wizard skin prefab or a warrior skin prefab.
I use custom properties to set the skin name and that works.
On the player object, I have this piece of code:
void OnPhotonInstantiate( PhotonMessageInfo info )
{
Debug.LogError("Skin: " + info.sender.CustomProperties["Skin"] );
if ( PhotonNetwork.isMasterClient )
{
GameObject skin = (GameObject)PhotonNetwork.Instantiate (info.sender.CustomProperties["Skin"].ToString(), Vector3.zero, Quaternion.identity, 0, null);
skin.transform.SetParent( transform, false );
skin.transform.localPosition = Vector3.zero;
skin.transform.localRotation = Quaternion.identity;
}
}
The result is as follows. There are 2 players. One has the warrior skin property and the other has the wizard skin property.
On MasterClient all is well. Each player has the correct skin, it is parented correctly and the rotation and position is correct.
On the remote client, one skin got create (let's say for warrior), in the centre of the world and it is not parented. The other skin (wizard) never got created.

What should I do to instantiate the skins, set their parents and position/rotation correctly on all clients?
Because I am a new, I would appreciate sample code if possible. Thanks for your help!


Viewing all articles
Browse latest Browse all 8947

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>