Ask or search…
Comment on page

Creating and Joining a Lobby

Create the Lobby Scene

First of all, create a scene named 0_scene.
  • The prefix 0_ helps us organize our scenes better.
  • Add it to Building Setting.
Next, rename our scene folder to _Scenes.
The "_" prefix ensures that our scenes always appear at the top of our Assets Hierarchy. This is necessary because some packages may use default names and potentially override our folder.
The new scene will look like below:

Create the Lobby UI

Here is everything we need to create in order to make Lobby work.
1st group:
  • Title (text): is unchangeable and always contains the LobbyID text.
  • ID (text): receives the lobby ID after a player creates or joins a lobby.
2nd group:
  • Title
  • InputMaxPlayer: defines the maximum number of players who can join the lobby.
  • Create Lobby button: sends a lobby creation request to Unity Lobby.
3rd group:
  • Title
  • InputLobbyCode: displays the lobby code for the lobby owner or allows players to enter an existing lobby code.
  • Join Lobby button: allows joining an existing Lobby, is disabled if players already have a lobby.
4th group:
  • Title
  • InputPlayerCount: is read-only, can use Text Mesh Pro for displaying the player count.
  • Start Game button: allows lobby creators to start the game.

Lobby Manager Script

All the Inputs and Buttons in the UI will will be controlled by a Lobby Manager Script, which facilitates the display and interaction within the lobby.
While there is not a specific document for the Lobby Manager Script, we'll gain an understanding of how it works as we explore the documentation for each element within the Lobby UI.
Here's a preview of what the Lobby Manager Inspector looks like. Take a moment to review it before we proceed.

The Assets structure

You don't have to adhere strictly to my approach, as it may not necessarily be the best practice. However, this is how I personally organize my scripts for the lobby.