Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by Cypras · Jan 06, 2014 at 06:32 PM · photonweb player hosting

Photon Network get players in a room

Hi,

I'm using the Photon Network, and I was wondering how to get the players that are currently in the room? Like their player name, etc.

Thanks.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
10
Best Answer Wiki

Answer by Caio_Lib · Mar 20, 2014 at 05:45 AM

Hi,

You can use:

PhotonNetwork.playerList - List of ALL player in the room.

Or you can use:

PhotonNetwork.playerName and PhotonNetwork.otherPlayers - Your player and list of others players.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image superluigi · Jul 20, 2015 at 02:49 AM 0
Share

How do we display the names as a string though. I have a UI.Canvas with a UI.Text child but I can't get it to display the name of the players. I have one UI.Text and it displays my name with

 inRoomPlayer1.text = PhotonNetwork.playerName;

Now I want to display the names of the other 3 players in the room. I've tried a bunch of lines, such as

 inRoomPlayer2.text = PhotonNetwork.playerList[1].name;

I've added things to the above code, I've created new variables to store the PhotonPlayer, no matter what I've tried so far though I haven't been able to get the playerName.

avatar image Caio_Lib · Jul 20, 2015 at 03:11 AM 0
Share

Hi superluigi, You could try:

 var playerList = new StringBuilder();
 
             foreach (var player in PhotonNetwork.otherPlayers)
             {
                 playerList.Append(player.name + "\n");
             }
 
             m_Text.text = playerList.ToString();

Hope it helps!

avatar image loliconest · Apr 10, 2016 at 07:15 PM 0
Share

Hello! I want to know that after you get the list of all player in the room, how can I access other script in a player object.

Like, each player has to have a photonView.cs attached, right? How can I then use it to access/refer other script which attach to the same object using the list I get from PhotonNetwork.playerList?

avatar image Caio_Lib loliconest · Jul 02, 2016 at 08:07 PM 0
Share

Hi loliconest, Using PhotonNetwork.otherPlayers you can identify players by ID, you can call RPC method passing ID as parameter and check if ID is equal to the current object.

Example: $$anonymous$$arco Polo Tutorial

Documentation: RPCs And RaiseEvent

avatar image
1

Answer by saadali211 · Mar 02, 2020 at 08:15 AM

here is how you list players name in current room in Photon Unity Networking PUN2

 public void AddAllActivePlayers()
     {
         Dictionary<int, Photon.Realtime.Player> pList = Photon.Pun.PhotonNetwork.CurrentRoom.Players;
         foreach (KeyValuePair<int, Photon.Realtime.Player> p in pList)
         {
             print(p.Value.NickName );
         }
     }


Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Photon Network Pong Game 0 Answers

Sending (and receiving) player names with Photon Networking 0 Answers

Photon Network Cant Destroy Player Objects 1 Answer

Using Photon to Send Screenshot to other Players 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges