简体   繁体   中英

Set NickName for photonplayers unity3d

I have a problem seeing the name of the client-side but in my master side names of the player is showing so what I did was like this

public override void OnPlayerEnteredRoom(Player newPlayer)
{
    PlayersName();
}

private void PlayersName()
{
    if (playerCount == 1)
    {
        playerNames[0].text = "Kingdom Player 1";
        playerNames[1].text = "";
    }
    else
    {
        playerNames[0].text = "Kingdom Player 1";
        playerNames[1].text = "Kingdom Player 2";
    }
}

public override void OnPlayerLeftRoom(Player otherPlayer)
{
    PlayersName();
}

Now it displays in both sides the problem is that it is not optimize well. Can someone help me, please?

In the photon, you have to check your current room players. You have too little change in your code. you can't use directly player count. after change, this code is working properly.

public override void OnPlayerEnteredRoom(Player newPlayer)
{
    PlayersName();
}

public void PlayersName()
{
    if (PhotonNetwork.CurrentRoom.PlayerCount == 1)
    {
        playerNames[0].text = "Kingdom Player 1";
        playerNames[1].text = "";
    }
    else
    {
        playerNames[0].text = "Kingdom Player 1";
        playerNames[1].text = "Kingdom Player 2";
    }
}
public override void OnPlayerLeftRoom(Player otherPlayer)
{
    PlayersName();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM