RPC Target

Hello.
I want to send an RPC call to a specific player. I know the other player name. How can i do that?

I guess i should use PhotonPlayer object. But how can i get it knowing only player name?

Comments

  • Hi,

    Yes, you can pass PhotonPlayer in RPC() call to send RPC to this player only.
    To find player by name, iterate PhotonNetwork.playerList and check 'name' property of each element.
  • Thanks.

    isn't there a simplier way? I think it will take too much time if there's about 1000 players in the room.
  • PUN does not have optimized player search by name or ID. But why do you need that?
    What does prevent you from keeping PhotonPlayer reference directly instead of name?
    In worst case you need one auxiliary array or dictionary for PhotonPlayer references.
  • my bad...

    Thanks for your reply.
  • SN_007
    SN_007
    edited July 2017
    vadim said:

    Hi,



    Yes, you can pass PhotonPlayer in RPC() call to send RPC to this player only.

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

    Dear Vadim! This task is very important for me also. But the question is not resolved for me - I'm sorry :) Do You can write a simple example code for calling and for PRC executing of this task?

    For example:

    private void CallingMethod() {

    int player_ID = PhotonNetwork.playerList[ 0 ].ID; // Only as example

    photonView.RPC( "RPC_PaintSpecificPlayer", PhotonTargets.???????, player_ID );

    // PhotonTargets.??????? - what target need to be specified?
    }

    [PunRPC]
    private void RPC_PaintSpecificPlayer( int player_ID ) {

    // ????? How I can paint the cpecific player with this ID in special color?
    }

    Thank You if You can help me...