- Home /
Multiplayer lan
I have a code for LAN multiplayer and it works on the same Laptop in two windows but it can't connect to other Laptops. Does this code require a certain type of network and does it even work on laptops? I also tried on some computers and it didn't work. Movement in the game is in a separate code and uses @RPC functions.
Here's the code for connection:
#pragma strict
public var connectionIP: String = "127.0.0.1";
public var connectionPort: int = 25001;
function OnGUI () {
if (Network.peerType == NetworkPeerType.Disconnected){
GUI.Label(new Rect(10, 10, 300, 20), "Status: Disconnected");
if (GUI.Button(new Rect(10, 30, 120, 20), "Client Connect")){
Network.Connect(connectionIP, connectionPort);
}
if (GUI.Button(new Rect(10, 50, 120, 20), "Initialize Server")){
Network.InitializeServer(32, connectionPort, false);
}
}
else if (Network.peerType == NetworkPeerType.Client)
{
GUI.Label(new Rect(10, 10, 300, 20), "Status: Connected as Client");
if (GUI.Button(new Rect(10, 30, 120, 20), "Disconnect")){
Network.Disconnect(200);
}
}
else if (Network.peerType == NetworkPeerType.Server){
GUI.Label(new Rect(10, 10, 300, 20), "Status: Connected as Server");
if (GUI.Button(new Rect(10, 30, 120, 20), "Disconnect")){
Network.Disconnect(200);
}
}
}
Answer by CliffracerX · Aug 14, 2014 at 12:27 AM
Your client is always trying to connect to 127.0.1 - in other words, your client is trying to connect to the same computer it's running on. If you add a textbox to change connectionIP, it should work, you'll just need to put in the other computer's IP to play.
Your answer
Follow this Question
Related Questions
Network connection problem 1 Answer
UNet SpawnWithClientAuthority Network Connection 0 Answers
Network problem 0 Answers
LAN NetworkTransport communication issue 1 Answer
Cannot connect directly in local network 0 Answers