Accessing a Player by his Actor number

The whole answer can be found below.

Please note: 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! And we offer you support through 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.

Accessing a Player by his Actor number

Paladin83
2019-03-09 12:25:33

Hallo.
Could someone please make a simple example how to access a player in a room by his Actor number.
I need to check if a Player has left the room.
I was trying something like....
if (PhotonNetwork.PlayerList.ActorNumber[1] == null) { then }
Thanks a lot.

Comments

JohnTube
2019-03-09 21:37:13

Hi @Paladin83,

I think you should make use of the callback IInRoomCallbacks.OnPlayerLeftRoom(otherPlayer).
Otherwise, there is a helper method Room.GetPlayer(int)

Player player = PhotonNetwork.CurrentRoom.GetPlayer(actorNumber);  
if (player != null && !player.IsInactive)   
{  
    // player is joined to the room  
}

Paladin83
2019-03-13 18:50:29

Thanks a lot.

Back to top