Search Unity

Get how many players connected and tell them how many players are connected

Discussion in 'Multiplayer' started by LiOn0X0HeaRt, Jul 2, 2015.

  1. LiOn0X0HeaRt

    LiOn0X0HeaRt

    Joined:
    Jul 14, 2014
    Posts:
    38
    Hi
    i want to make every player that enters the game sends that he entered
    and add 1 to players connected
    and then i want him to know how many players are connected
    the thing is this playersConnected int

    should be sent and received but how and from who and where to store it
    i can't figure this at all i :(
     
  2. Necromantic

    Necromantic

    Joined:
    Feb 11, 2013
    Posts:
    116
  3. peterept

    peterept

    Joined:
    Dec 6, 2012
    Posts:
    22
    NetworkServer is only callable by the server right? So only the server knows the number of players? And it could sync the list out to the clients?
     
    ceitel likes this.
  4. SuperNeon

    SuperNeon

    Joined:
    Mar 16, 2014
    Posts:
    85
    You can register all spawned Player and get your list of connected client.
    I did that to display some info about the connected players.
     
  5. peterept

    peterept

    Joined:
    Dec 6, 2012
    Posts:
    22
  6. SuperNeon

    SuperNeon

    Joined:
    Mar 16, 2014
    Posts:
    85
    Hi !

    I have a GameManager with a function to register it.
    In the callback OnStartClient I call this function.

    For exemple:
    Code (CSharp):
    1. public class Player
    2. {
    3.    void OnStartClient()
    4.    {
    5.          GameManager.RegisterPlayer(this);
    6.    }
    7. }
    8.  
    9. public class GameManager
    10. {
    11.        static List<Player> m_Players = new List<Player>();
    12.  
    13.        public static void RegisterPlayer(Player player)
    14.        {
    15.             m_Players.Add(player);
    16.         }
    17. }
     
    Sekkizan, megabrobro and liortal like this.