Search Unity

Help Wanted Unity PUN2: UI position relative to player

Discussion in 'Multiplayer' started by ScaRvps, Jul 16, 2020.

  1. ScaRvps

    ScaRvps

    Joined:
    May 29, 2020
    Posts:
    4
    Hi, I'm newbie to networking and trying learn. I'm creating a multiplayer game and want the local Player's info always on bottom left and other player's on top right. How to achieve this? Any help is appreciated. Screen Shot 2020-07-15 at 10.19.10 PM.png
     
  2. ksc_3899

    ksc_3899

    Joined:
    Jan 1, 2019
    Posts:
    29
    You can get a list of the players in your room from Awake function and loop through each player, check if it is self and then accordingly set the positioning of that player.
     
    ScaRvps likes this.
  3. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,688
    For each player, the PhotonNetwork.LocalPlayer is .. the local player. :)
    The other player (in a 2 player game) can be found as: LocalPlayer.GetNext().
    So the scene you need shows the LocalPlayer in the bottom left and the LocalPlayer.GetNext() in the top right.

    If someone leaves the room and someone else joins, that new Player.ActorNumber may be 3 or higher.
    There is a PlayerNumbering.cs in the package, which assigns players to a list of spots/numbers without gaps, so you always have player 1 and 2. This can be associated with a list of colors, etc.
     
    ScaRvps likes this.
  4. ScaRvps

    ScaRvps

    Joined:
    May 29, 2020
    Posts:
    4
    Thank you for your reply. I was able to get what I want. I was able to loop through the player and set the position as suggested by @ksc_3899. I'm developing a turn based multiplayer game, so the GetNext() you suggested would help me to switch the turns I believe (yet to go there).
     
  5. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,688
    Also have a look at the PunTurnManager in the Utilities folder. Might help with some boilerplate code for turns.
     
  6. ScaRvps

    ScaRvps

    Joined:
    May 29, 2020
    Posts:
    4
    Sure, will do. Thank you!
     
  7. ScaRvps

    ScaRvps

    Joined:
    May 29, 2020
    Posts:
    4
    I was able to get the turn working and stuck on something else.
    The game I’m developing is a board game with tiles. Each player will have 6 game pieces that will move on a path. Path consists of tiles and it will be different for each player. Tile has two variables, one bool - is the tile taken and other the game piece object that occupies it. Now, I want to sync these variables across. There are 49 tiles in total, so I don’t want to have photon view and observed component. These variables need to be synced only when the game piece moves. So, having an RPC made sense but that’s where I’m having the trouble. I won’t be able to use the photon view of the game pieces since only the local player game pieces will have the path on them. Any suggestions on how to sync these variables across?

    UPDATE: Nevermind! I created the path for all the game piece and that solved the issue. Thank you anyways!
     
    Last edited: Jul 21, 2020
unityunity