Description: This passage is mainly about the lobby login. The writer shows us how to implement Unity’s multiplayer server system to build a matchmaking system for the lobby, which will allow us to connect with others without the need for letting others know the IP address.
Welcome back, this is part 2 of the network lobby tutorials series, in the last tutorial we set up the network lobby system over the top of the multiplayer car basic networking demonstration that we have built in a previous tutorial, and we went through how to select the dedicated server, and to join a game on your local machine or in a local area network.
What I’m going to go through today is to use unities cloud-based servers which use this part of this Lobby system, so to begin with, you have to set up your project as a multiplayer system with unity, which means that you need to turn on those services.
Now to do that in unity, you’ll find up in the top corner, a little cloud button is here, now when you click on that cloud button, it will bring up a service tab, and it will ask you to login, then once you log in, you’ll get this panel come up where you can add other services to your game if you like.
Now we’re interested in this multiplayer one, so let’s add multiplayer service to this network cars by clicking on it, now it will come back to you and ask you to go to the dashboard to configure it, so if you click on this link here, it’s going to open up your web browser, and it will take you to an area where you need to configure the lobby.
So we’ve got our max players per room setting which we’ve got as 4 in our actual code, so we can click on save for that, and then it’ll spend a bit of time configuring, and then you’ll get this panel come up which is all very fine, and you can click on save, and then when you switch back to unity, there will be a refresh button to bring all of the configuration into your project.
Now this is all set up to use unities servers for your multiplayer project, so all we have to do now is to build it out and run and test it as we have done before, so this time I’m going to run in the editor one version of it.
Now the first thing that we want to do is to create a game on the service, now if we click on list servers, we can see that there’s no game currently running, because no one has created a version of our game, so let’s go back, that means that we create the first version of our game to run, so let’s call our server test lobby one and go to create it.
Now it will connect and then it will sit here and wait for players as before, now it’s not going to start until it gets to players, and it’s also not going to allow more than four players in there, so this is running waiting for people to join, let me grab another version.
Now what I can do is that I’m running the same game, I can go list servers, and it’s going to connect to the Unity servers, and ask for a list of the servers running this particular game and their names, so you can see here that we’ve got test lobby one comes up, and that’s the one being running over here.
So I can join that, so you can see that the players have now come up here, and the player two can join now, player 1 hasn’t joined before, they are running the server, so if I now join in here, the match will start, and then we end up in the same position where we are before.
So my other player has gone, I’ve still got the escape button that will bring up that there, but now we’re using the unities servers to match and make our actual game servers, so we can run the server on this machine, and connect from another machine through the unity services which means that we don’t need to be telling everybody what our IP address is.
It’s going to come up there in that list of servers with the game name that we’ve given it, back in this spot here, and that is to setting up that as well, it’s so simple for something that’s very complex, if you want to go digging around in the code to discover how complex all of the codes are.
But write it yourself when the wonderful people at unity have supplied us with this great little tool, so that’s the end of the part 2 tutorial, what I’m going to do in the next tutorial is to go back to that player info prefab that sets the player name and the color, and show you how to pass that through to the car, so we can set the players name and change the color of the car for you, it’s fun networking and I will talk to you in part three.