Displaying names of players in my Team(Distinguishing players)

Options
I wana display names of players on top of head in my team.
I have script displaynames which does it. Heres code
int myid = GetComponent<PhotonView>().ownerId; PhotonPlayer thisplayer = PhotonPlayer.Find(myid); Team thisteam = thisplayer.GetPlayerTeam(); if (myteam != thisteam) this.enabled = false;
So i am disabling displayname script on enemyteam players.
Heres problem
Lets see player1 and player2 are in same team.
player1 joins the game 1st then player2 joins.
Now playeer1 can see name of player2 but player2 cant see name of player1 bec he has joined later.
So any1 knows how to get this working??

Comments

  • [Deleted User]
    Options
    Hi @sandy410,

    have you taken a look at PunTeams script which is included in the PUN package from the Asset Store? PunTeams uses the Player Properties to store the player's team. It also have a few extensions for setting and getting the team value. When using the Player Properties you can implement the OnPhotonPlayerPropertiesChanged callback and compare the received team value (check if it exists before) to your own by using PhotonNetwork.player.GetTeam() and (de-)-activate the name display based on this result.

    There are a few other ways to handle what you want to achieve. For example you can also use RPCs or RaiseEvent calls with Interest Groups or a combination of OnJoinedRoom (for newly connecting players) and OnPhotonPlayerConnected (for already joined clients) callbacks.
  • sandy410
    Options
    Hi can you give an example of how to do this with OnJoinedRoom or OnPhotonPlayerConnected
  • Well, honestly using OnJoinedRoom and OnPhotonPlayerConnected is not the best choice, so just ignore those for the wanted behaviour. What you can do instead is to use the client's NickName property by accessing the PhotonView component: photonView.owner.NickName. E.g. in the Start() function of a script attached to the character prefab you can check if the player is in your team (needs to be set up before) and if the character is a teammate you can use his name as mentioned before. Might look like this:
    void Start()
    {
        if (clientsTeam == myTeam)
            name = photonView.owner.NickName;
    }