Search Unity

Set names of several players in UI Text

Discussion in 'Multiplayer' started by em-art, Apr 22, 2022.

  1. em-art

    em-art

    Joined:
    Apr 17, 2020
    Posts:
    2
    Hi everyone!.

    In a Multiplayer Board Game for two players like Chess, I got the UI Canvas wich displays the name of each player in UI Text using the code below in a "PlayerManager.cs" script wich is attached to the Player Prefab.

    But what's about when the Board Game is for three, four or more players? How can I set the name of the next players whose join the game in each UIText: playername3, playername 4...?

    Any help is appreciated

    Thanks a lot

    *********PlayerManager.cs****************


    public Text playername1;

    public Text playername2;

    public Text playername3;

    public Text playername4;


    if(photonView.IsMine)

    {

    playername1.text = photonView.Owner.NickName;


    }

    else

    {

    playername2.text = photonView.Owner.NickName;


    }


    (The question is...How can I continue this loop for three players or more?...)