We have released a beta version of the Networking Lobby Example on the Asset store .
This pack contains a multiplayer lobby using either the Networking matchmaker service (https://multiplayer.unity3d.com) or a manual connection by IP address.
NOTE : This is a beta! Some bugs may be expected. You can help make it better by please reporting any problem you have with this package using the in-editor bug reporter!
USAGE
Instructions are included in Standard Assets/Network/Instruction.txt
- You will need two scenes : one for the lobby, one for the game
- These scenes need to be added to the Build Settings window. (File > Build Settings)
- Drop the LobbyManager Prefab into your scene
- In the LobbyManager script component, drop your scenes into the fields “Lobby Scene” and “Game Scene”.
- Drop your game player prefab into “Game Player Prefab” slot. This prefab will need to have a script deriving from NetworkBehaviouron it. (See Spaceship in SamplesScene/Prefabs for an example of a Game Player Prefab)
- Set “Min Player” to the minimum number of players needed to start a game (0 = no minimum)
Additionally, if you want to pass data from the lobby player (the sample one has a name and a colour) , you can derive a script from LobbyHook (see SampleScenes/Scripts/NetworkLobbyHook for an example) and add it to your own LobbyManager
Please note that the prefab will output information / warnings in the Console. This is normal! To control the amount of logging output by the Lobby, in the LobbyManager script inspector change the Log Level parameter.
Lobby screen
You can add a local player with the Add Local Player “+” icon.
The Remove Icon will be grayed out for other clients players (apart if you are the server) or if you are the only local player (you can’t remove all your players!)
Game Lobby Example
You can create a lobby:
- Through the Matchmaker by clicking Create after entering a name
- For Direct Connection by clicking Play and Host.
Both will create a local server on your machine and connect you to it.
Other players can then join by doing
- “List Servers” (if the match was created with Matchmaker)
- By entering your IP address (if you created with Play and Host)
NOTE : Direct IP can fail if you are behind NAT, firewall etc… It is recommended to use the matchmaker for non LAN game!
Matchmaker
To be able to use the matchmaker, you need to create a project in the Unity Services tab (Window > Unity Services and select Multiplayer in the list)
Sample Asteroid
The directory SampleScenes/Scenes contains two samples scenes for a simple networked game of Asteroid. It’s a simple example here to show how to interact between a lobby and a game.
Open the lobby scene to see how a lobby is set.
The script SampleScenes/Scripts/NetworkLobbyHook.cs will show you how to pass info from the LobbyPlayer to the GamePlayer.