![]() To achieve this, we need to send a request to the master server to get a list of HostData. We now have the functionality to create a server, but can not yet search for existing servers or join one of them. Thanks to jeff77k for this addition! Joining a server You can download and run your own MasterServer locally. This MasterServer is run by Unity and could be down due to maintenance. Afterwards the button should disappear (1B). If you press this button, a message should be shown in the console indicating you just initialized a server. ![]() When starting the project, all you should see now is a start server button (1A). Now it is time to test what we developed so far. ![]() We only want to see these buttons if we have not started a server or joined one, so the button will show itself if the user is neither a client nor a server. To test it out we create buttons using the Unity GUI. ![]() For now, we are happy to get feedback telling us the server is actually initialized.Īll we need now is some form of input to let us actually start the server when we want to. If the server is successfully initialized, OnServerInitialized() will be called. MasterServer.RegisterHost(typeName, gameName) Network.InitializeServer(4, 25000, !Network.HavePublicAddress()) Private const string gameName = "RoomName" Private const string typeName = "UniqueGameName" Add these lines to the NetworkManager script. The room name can be any name, and in our case we eventually used the player name. For the server registration the name of the game should be unique, otherwise you might get in trouble with others projects using the same name. The initialization requires a maximum amount of players (in this case 4) and a port number (25000). To create a server, we need to initialize it on the network and register it to the master server. It will handle hosting a server or connecting to an existing server. Add this empty script to an object in the scene, either the camera or an empty game object. So let’s get started! In the new Unity project, create a new C# script named “NetworkManager”. It’s explained in Javascript, but covers the same content as the first three paragraphs. Networking was a new topic for us and I found this video tutorial very useful to start with.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |