- Home /
Multiplayer Server?
I'm trying to make a multiplayer game and I am already able to make two characters and two different parts of the screen and one character uses WASD and the other uses arrow keys. What I am trying to do is make a server so that two players from two computers can go online and play each other. I know this is a very hard question and will not only require Unity and Javascript but also other application things. I'm confused and just a little help would be great. Thank you
Answer by Vasir_ · Feb 03, 2013 at 01:35 AM
Take a look at these pages: http://docs.unity3d.com/Documentation/Manual/NetworkedMultiplayer.html
http://docs.unity3d.com/Documentation/Components/net-MasterServer.html
http://docs.unity3d.com/Documentation/Components/net-UnityNetworkElements.html
I believe the Unity website has a sample project for connecting to a client, but I can't locate it at the moment.
Answer by TKS_Keeper · Jun 17, 2014 at 07:12 PM
I've found this simple walkthrough to be invaluable when I was setting up our very first client/server interface. This uses the built in unity functionality to create a multiplayer game.
The fundamental steps are:
Register the server with the
Network.InitializeServer
andMasterServer.RegisterHost
Create a "Host Browser" of some sort which is populated with host data via
MasterServer.RequestHostList
andMasterServer.PollHostList
Join the server from the client with
Network.Connect
by passing it the HostData from the users selection from the "Host Browser"Instantiate the "Player" object via the client to create an object which is "owned" by the client. (Said object should only react to inputs from the owning client using
if(networkView.isMine)
checks)Create OnSerializeNetworkView function overrides on all scripts which will require network state synchronization. (Use RPC calls ONLY when absolutely necessary, as an RPC call is much higher cost/ performance impact than a state synchronization)