GameObject from PhotonPlayer
Options
I want to be able to make a generic List of all of the players in the room. But using
foreach (PlayerUser up in PhotonNetwork.getPlayerList) {
//Mind you I'm on my phone writing this, you guys have the just of the code.
// How do I convert "up" or simply return the GameObject that the PlayerUser belongs to?
}
foreach (PlayerUser up in PhotonNetwork.getPlayerList) {
//Mind you I'm on my phone writing this, you guys have the just of the code.
// How do I convert "up" or simply return the GameObject that the PlayerUser belongs to?
}
0
Comments
-
In one of components of the GameObject override OnPhotonInstantiate and set GameObject to player.TagObject to access it later0
-
I called OnPhotonInstantiate(PhotonMessageInfo info)
inside of my player prefab and the Debug.Log doesnt appear in console. Any ideas?0 -
You dont need to direct call OnPhotonInstantiate, but you call PhotonNetwork.Instantiate and photon will run the callback defined in your prefab by OnPhotonInstantiate.
here it is an example:public class PrefabAnyComponent : PunBehaviour { public override void OnPhotonInstantiate(PhotonMessageInfo info) { //Assign this gameObject to player called instantiate the prefab info.sender.TagObject = this.gameObject; } }
0 -
I implemented it onto my Player, but when it instantiates, and I debug the gameObject's name, it returns the name of another of my gameobjects I have in the scene that implements all of my GUI and things for the login menu.
I think I could make a huge workaround, do you know of a way I could have a static List and store all of the players currently in the room? The biggest problem I've had with that, is the List isnt being synced to every player. Even if it's static. How do i keep 1 single list?0 -
Use
PhotonNetwork.playerList
to get the list of players in the current room.
To access all gameObjects instantiated in the scene:var photonViews = UnityEngine.Object.FindObjectsOfType<PhotonView>(); foreach (var view in photonViews) { var player = view.owner; //Objects in the scene don't have an owner, its means view.owner will be null if(player!=null){ var playerPrefabObject = view.gameObject; //do works... } }
1 -
That is genius! Thank you very much!0