How to check which player belongs to the client.

Options
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
    Options
    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.
  • 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
  • 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