Search Unity

Keeping Track of Spawned Player

Discussion in 'Multiplayer' started by nm8shun, Oct 24, 2016.

  1. nm8shun

    nm8shun

    Joined:
    Jul 14, 2007
    Posts:
    476
    I need to track auto-spawned players once they've joined the game.

    What I've currently done (that doesn't work), is build in a little network check script that's attached to the player, so that on Start, it tries to plug itself into some variable slots on another GameObject's (called GameManager) script. This GameManager has a NetworkIdentity component on it.

    Code (csharp):
    1.  
    2. GameObject player1
    3. GameObject player2
    4.  
    5. .....
    6. public void AddPlayer(GameObject countedPlayer)
    7. {
    8.         if (player1 == null) {
    9.            player1 = countedPlayer;
    10.         } else {
    11.             player2 = countedPlayer;
    12.         }
    13. }
    14.  
    When the Server client plays, this works great; but when the client attempts to do this, it never seems to reach out and plug in. It seems like the Client (when it's spawned) is either not able to find the GameManager or the GameManager doesn't update to show that it has populated the player2 slot. What have I got wrong?