Find PhotonPlayer by name.

Options
Hello, I need to find photonplayers by name. I have been searching for a solution for a while but haven't found anything useful. There's only a function to find photon player by ID but that won't work for what I'm trying to do.

This is what I want to do:

When an admin player types in the chat /kick + playername I want to find a photon player by name by using substring with the chat text. Same with players private messages - when a players types /pm I want them to be able to pm a specific player.
if(inputField.StartsWith("/pm "))
				{
					string sendTo = inputField.Substring(4, inputField.Length);
					photonView.RPC("Chat", PhotonPlayer.Find (sendTo), inputField, PhotonNetwork.player.name);
				}
				if(inputField.StartsWith("/kick ") && (PhotonNetwork.isAdmin || PhotonNetwork.isGameMaster))
				{
					string kick = inputField.Substring(4, inputField.Length);
					PhotonNetwork.CloseConnection(PhotonPlayer.Find (kick));
				}

I don't know why there is no such function.

Comments

  • vadim
    Options
    Hi,

    To find player by name, iterate PhotonNetwork.playerList and check 'name' property of each element.