I’m trying to make a system to place a player’s name above them when they spawn. I have PhotonNetwork.owner for their name, the only problem is the most efficient way to update their name. Using something like:
somePlayerThatIGrabbedInAForeachLoop.TextMesh.text = PhotonNetwork.owner;
that would work, but since it’s in update, that seems a little inefficient. I’d prefer to have one function like void UpdatePlayerNames()
where it just uses a foreach loop to grab all players and updates all their names so when a player joins or a player changes their names it will update all names (which isn’t a big deal if it does them all, not just the one that changed). Anyone got such function that is called when a player joins the lobby/game/server? THanks
Edit : https://doc-api.photonengine.com/en/pun/current/class_photon_network.html
The best thing to do is check the PDF that comes with the package. Here are some common functions called by Photon :
// Photon Auto Called Functions
// ----------------------------------------------------------------------------------------------
// OnJoinedLobby() - called when the Photon Network is connected to with ConnectUsingSettings
function OnJoinedLobby()
{
Debug.Log( "OnJoinedLobby() : Hey, You're in a Lobby ! " + PhotonNetwork.PhotonServerSettings.ServerAddress );
}
// called when a room is created by the player
function OnCreatedRoom()
{
Debug.Log( "OnCreatedRoom() : You Have Created a Room : " + PhotonNetwork.room.name );
}
// called when a room is joined by the player
function OnJoinedRoom()
{
Debug.Log( "OnJoinedRoom() : You Have Joined a Room : " + PhotonNetwork.room.name );
}
// OnPhotonRandomJoinFailed() - called when JoinRandomRoom() fails, no rooms available
function OnPhotonRandomJoinFailed()
{
Debug.Log( "OnPhotonRandomJoinFailed() : No existing rooms ...." );
}
function OnPhotonPlayerDisconnected( other : PhotonPlayer )
{
Debug.Log( "OnPhotonPlayerDisconnected() " + other.name ); // seen when other disconnects
}
function OnConnectedToMaster()
{
Debug.Log( "OnConnectedToMaster()" ); // havn't seen this yet
}
function OnMasterClientSwitched() // definitely seen when the host drops out, not sure if it's when becoming master or just when switching
{
Debug.Log( "OnMasterClientSwitched()" );
if ( PhotonNetwork.isMasterClient )
{
Debug.Log( "isMasterClient " + PhotonNetwork.isMasterClient ); // called before OnPhotonPlayerDisconnected
}
}
function OnPhotonPlayerConnected( other : PhotonPlayer )
{
Debug.Log( "OnPhotonPlayerConnected() " + other.name ); // not seen if you're the player connecting
}
Try working with PhotonTarget.AllBuffered, see if that helps, I believe creating a public void, followed bby some kind of if statement may work