Here’s a very simple networking script from a tutorial that I’m trying to get working with Unity 3.4. Although it doesn’t throw any errors it also doesn’t seem to be connecting the server and client. Here’s the script:
var remoteIP = "127.0.0.1";
var remotePort = 25001;
var listenPort = 25000;
var useNAT = false;
var yourIP = "";
var yourPort = "";
function OnGUI () {
// Checking if you are connected to the server or not
if (Network.peerType == NetworkPeerType.Disconnected){
// If not connected
if (GUI.Button (new Rect(10,10,100,30),"Connect")){
// Connecting to the server
Network.Connect(remoteIP, remotePort);
}
if (GUI.Button (new Rect(10,50,100,30),"Start Server")){
// Creating server
Network.InitializeServer(32, listenPort, useNAT);
// Notify our objects that the level and the network is ready
for (var go : GameObject in FindObjectsOfType(GameObject)){
go.SendMessage("OnNetworkLoadedLevel", SendMessageOptions.DontRequireReceiver);
}
}
// Fields to insert ip address and port
remoteIP = GUI.TextField(new Rect(120,10,100,20),remoteIP);
remotePort = parseInt(GUI.TextField(new Rect(230,10,40,20),remotePort.ToString()));
}
else{
// Getting your ip address and port
ipaddress = Network.player.ipAddress;
port = Network.player.port.ToString();
GUI.Label(new Rect(140,20,250,40),"IP Address: "+ipaddress+":"+port);
if (GUI.Button (new Rect(10,10,100,50),"Disconnect")){
// Disconnect from the server
Network.Disconnect(200);
}
}
}
Anyone see why it’s not working?