How do I make a list of players in the current room with nicknames?
The whole answer can be found below.
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).
How do I make a list of players in the current room with nicknames?
Seth01Master
2022-04-28 13:36:58
Hi!
I would like to make a system where you can vote kick people out of a lobby if they are hacking, cheating, ect.
But, I cannot find a way to get the nicknames of all players in the current room! I tried using
foreach(Player player in PhotonNetwork.PlayerList)
{
Debug.Log(player.NickName);
}
but it keeps giving me an error and underlines "Player" in red with the text:
The type or namespace name 'Player' could not be found.
How am I supposed to define 'Player', or how should I go about making a player list?
Thanks!
Comments
You are not supposed to define it. It should be defined.
Is the IDE also complaining about PhotonNetwork being unknown?
It could be an issue with the Visual Studio package of Unity, which is known to sometimes generate incomplete project files (for the IDE). Check the Package Manager if there is an update. Generate the files again (there is a button somewhere but I don't recall where).
That usually helps.
Which version if Unity do you use? And which PUN version?
Seth01Master
2022-04-29 14:35:22
Sorry for not responding sooner!
I actually solved the problem by adding:
using Photon.Realtime;
The rest of my code seemed to work fine without it (even though it used "using Photon.PUN"), but adding it seemed to solve the problem.
Thanks!
Back to top