Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    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.