Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  4. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Get LocalPlayer gameobject on a client, The one spawned by AddPlayerForConnection?

Discussion in 'Connected Games' started by trappist-1, Sep 14, 2018.

  1. trappist-1

    trappist-1

    Joined:
    Mar 26, 2017
    Posts:
    277
    I have a lobby manager that uses AddPlayerForConnection to add palyers to the lobby panel.

    But how do I find the Gameobject that was added on a client?

    Network.player - has no reference to any transforms or script componets.
    NetworkManager.singleton.client - has no reference to any transforms or script componets.

    What am I missing? Why can't I simply reference the local lobby player gameobject?

    Only way I can imagine now is loop through all LobbyPlayers in scene and search for the one that isLocalPlayer = true?

    If that is the only way then that is absolutely insane!
     
    Last edited: Sep 14, 2018
  2. trappist-1

    trappist-1

    Joined:
    Mar 26, 2017
    Posts:
    277
    I think I found it after stepping back for a moment:

    Code (csharp):
    1. var lobbyInfo = NetworkManager.singleton.client.connection.playerControllers[0].gameObject;