![]() You need to keep one more setting in mind before connecting to a server or when initializing a server, that is the “eNat” bit you see just above the corresponding connection/initializing code. Do note that you can always lower the maximum numbers connection on a running server, but you can never set it higher than the value you used when initializing. This takes a port and maximum allowed number of connections as argument. TO start a server a similarly easy function is called: Network.InitializeServer. We call the Network.Connect function to connect clients to servers, this function takes IP, port and optionally a password as arguments. We use the provided networking status “Network.peerType” to easily check our current connection status. The GUI function is divided in four parts For servers, connected clients, connecting clients and for disconnected clients. The two variables at the top of the script (connectToIP and connectPort) are used for capturing the input from the GUI field, these values are used when pressing the button to connect. The code should be pretty much self explanatory, however, we'll deal with the most important parts briefly. All code that has been used in this tutorial can be found in the OnGUI() function, have a look at this function and ensure you understand how it works. Have a look at the file “Tutorial 1/Connect.js” in your favorite editor. ![]() This was all very easy luckily the code is not much harder. You should now see “Connection status: Client!” and “Connection status: Server!” on your two instances. Start the scene in the editor as well and click on “Start a server” (using the default values for IP and port) Click on “Connect as client” in the webplayer. This scene consists of one camera, one gameobject with the Connect script attached to it and one gameobject to display the scenes title. Open the very first tutorial scene: The scene can be found at “Tutorial 1/Tutorial_1”. Tutorial 1: Connect & Disconnect Let's get you going! You can find this option at “Edit → Project settings → Player”. ![]() Otherwise you would not be able to connect to your server when running the client in the foreground. This will keep the servers game running in the background. For your own projects ensure the option “Run in background” has been turned on to be able to run a server in the background without it going to sleep. In case you want to use the tutorial assets in a project of your own, do mind that one projects setting has been modified in this tutorial project. During this tutorial you're advised to run the server in the editor game view, and a client in a webplayer. ![]() Multiplayer isn't much fun to debug since you need to have two instances of your game running (server and client). It is assumed you have already made yourself familiar with the unity editor and basic scripting, if not: check out the unity (video) tutorials. How to use this tutorial? Combined with this document is a zip file containing the unity project which is used in this tutorial. If you made something exciting thanks to this tutorial, let me know! In fact the first unity game we made featured multiplayer it's that easy to add! Our multiplayer games include: Crashdrive 3D, Cratemania, Surrounded by Death, Verdun Online and our current upcoming multiplayer challenge is Hyberon. We've been concentrating on unity multiplayer since the very beginning. You are advised to read this document from start to end, but if you are picking things up quickly you can have a look at the examples yourself and fall back to this document whenever you need more details.Ībout the author This tutorial is written by Mike Hergaarden (“Leepo”) from M2H (We've been using Unity for over two years now, though most of our unity development time has been spent in the past few months. This tutorial features many examples from small (but important) techniques to a real FPS game. With that in mind I decided to join the UniKnowledge contest and finally give the community a networking tutorial, that I hope, is all you need to create a networked game. When I started unity networking the networking example was a bit too confusing A proper networking example should have independent examples so you know where to look for something within seconds. 16 Example 4: FPS game.17 Tips.18Ībout this tutorial I always thought Unity needed a proper networking tutorial. By Mike Hergaarden - Last edit: 29-10-2009Ĭontent About this tutorial.2 About the author.2 How to use this tutorial?.3 Tutorial 1: Connect & Disconnect.4 Tutorial 2: Sending messages.6 Our very first multiplayer scene.just one player though!.6 Tutorial 2A: Server plays, client observes, no instantiating.6 Tutorial 2B: Server and client(s) play, with instantiating.9 Tutorial 3: Authoritative servers.10 Further network subjects explained.12 Real life examples.15 Example 1: Chatscript.15 Example 2: Masterserver example.15 Example 3: Lobby system.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |