Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Pass Data from NetworkLobbyPlayer to GamePlayer

Discussion in 'Multiplayer' started by AllMightyNico, Aug 10, 2015.

  1. AllMightyNico

    AllMightyNico

    Joined:
    Jun 12, 2015
    Posts:
    14
    Hello Folks,

    I'm creating an RTS game with a lobby, in which the player can choose the spawnposition, faction, color and so on. My question is, how do you pass this information to the actual player pawn, when the instance gets created?

    Best wishes
    Nicolas
     
  2. HugoZandel

    HugoZandel

    Joined:
    Mar 11, 2014
    Posts:
    52
    You need to extend the NetworkLobbyManager and override OnLobbyServerSceneLoadedForPlayer.

    From the doc :
    http://docs.unity3d.com/Manual/UNetLobby.html

    Code (CSharp):
    1.     // for users to apply settings from their lobby player object to their in-game player object
    2.     public override bool OnLobbyServerSceneLoadedForPlayer(GameObject lobbyPlayer, GameObject gamePlayer)
    3.     {
    4.         var cc = lobbyPlayer.GetComponent<ColorControl>();
    5.         var player = gamePlayer.GetComponent<Player>();
    6.         player.myColor = cc.myColor;
    7.         return true;
    8.     }
     
    Last edited: Sep 2, 2015
    unity_U4rY6T_9hPhqdQ likes this.