The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

How to check which player belongs to the client.

brannydonowt
2015-03-20 19:36:05

Hey there,

I've been trying to create a shop for my multiplayer game but I am having some problems because I am not sure how to access the variables for the player using the shop because I don't know how to check.

I.E. There are 4 people in a game, one of them is using the shop and buys an item. How would I know which player is buying the item?

I am using the latest version of Unity, and the latest version of PUN.

I'm not sure if there are any other ways to do what I am trying to do, but if you have any that aren't too complicated, be sure to tell me :)

Any help would be appreciated, thank you for your time.

Comments

dontonka
2015-03-20 20:59:47

Hello Branny,

In Photon the way to identify a specific player is by getting a PhotonPlayer object of such player, and using ID or name property of that object to differentiate players. In my game I always identify player by their name, which are unique in the context of my game.

PhotonNetwork.player is returning the local player. PhotonNetwork.playerList give you a list of all the player in the room.

http://doc-api.exitgames.com/en/pun/current/pun/doc/class_photon_network.html http://doc-api.exitgames.com/en/pun/current/pun/doc/class_photon_player.html

Hope this helps :D

Cheers, Don T.

brannydonowt
2015-03-20 22:16:12

@dontonka wrote:

Hello Branny,

In Photon the way to identify a specific player is by getting a PhotonPlayer object of such player, and using ID or name property of that object to differentiate players. In my game I always identify player by their name, which are unique in the context of my game.

PhotonNetwork.player is returning the local player. PhotonNetwork.playerList give you a list of all the player in the room.

http://doc-api.exitgames.com/en/pun/current/pun/doc/class_photon_network.html http://doc-api.exitgames.com/en/pun/current/pun/doc/class_photon_player.html

Hope this helps :D

Cheers, Don T.

Ah, okay... So how would I go about actually putting this into code? I have a hard time converting text into code if that makes any sense, sounds kinda stupid.

But, I'm just having a hard time wrapping my head around it... How could I access the Photon.Instantiated gameObject so that I could play around with the components on there?

Thank you for the reply

FamerJoe
2015-03-22 14:05:52

I haven't actually tried this, but when you instantiate the player, set the TagObject to your player gameobject for later reference:

playerGameObject.GetPhotonView().owner.TagObject = playerGameObject;

So later, you could reference the player's gameobject via:

PhotonNetwork.player.TagObject

Back to top