PhotonPlayer to gameObject?

How to get a gameObject of all players in the room? To get for example a component? It's seems simple but I cannot find the way to do that. A PhotonNetwork.playerList provides us with PhotonPlayers and now how to get their gameObjects?

Best Answer

Answers

  • Akrosh
    Akrosh
    edited June 2018
    Hi @Tomza

    Whenever a player connect you get response in void OnPhotonPlayerConnected(PhotonPlayer newPlayer) you have to instantiate a object and assign player details what ever you want to that object
  • Hi Akrosh, thank you for your answer.
    For example, I have two players spawned in the game and I need to get a component, scripts, to call a function on them. How to do that?
  • foreach(PhotonPlayer player in PhotonNetwork.playerList){
    MK_UIController mk_UIController = player.[SOMETHING].GetComponent();
    mk_UIController.AddMessage("Player " + other.NickName + " Left Game.");
    }

    How to iterate through the list of players to get their components so that I can call a function on them? What should be instead of the SOMETHING placeholder so that the code works? Hope it is clear what I meant.
  • Tomza said:

    foreach(PhotonPlayer player in PhotonNetwork.playerList){
    MK_UIController mk_UIController = player.[SOMETHING].GetComponent();
    mk_UIController.AddMessage("Player " + other.NickName + " Left Game.");
    }

    How to iterate through the list of players to get their components so that I can call a function on them? What should be instead of the SOMETHING placeholder so that the code works? Hope it is clear what I meant.

    Did you ever figure this out? This is the EXACT issue I'm dealing with