PhotonPlayer to gameObject?
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).
PhotonPlayer to gameObject?
Tomza
2018-06-01 13:29:11
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?
Comments
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?
lennart862
2018-06-04 23:43:48
Hi @Tomza,
that's easy to do:
Create a new gameobject in your scene. Name it "Network". Don't add a photon view to it.
Add a script to that game object. The script contains something like that:
public List
In the script which is attached to your player gameobject write:
GameObject Network = GameObject.Find("Network");
Network.GetComponent
If you want to get the player gameobject from another player do for example:
int HPOfPlayer2 = Network.AllPlayers.ToArray()[1].GetComponent
foreach(PhotonPlayer player in PhotonNetwork.playerList){
MK_UIController mk_UIController = player.[SOMETHING].GetComponent<MK_UIController>();
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 wrote:
foreach(PhotonPlayer player in PhotonNetwork.playerList){
MK_UIController mk_UIController = player.[SOMETHING].GetComponent<MK_UIController>();
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
Back to top