Search Unity

  1. Unity 2019.1 beta is now available.
    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. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    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:
    421
    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:
    421
    I think I found it after stepping back for a moment:

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