Server Network with Public IP

Hello,
I have this code:

#pragma strict
#pragma implicit
#pragma downcast

var connectToIP : String = "127.0.0.1";
var connectPort : int = 25001;

function OnGUI ()
{
	if (Network.peerType == NetworkPeerType.Disconnected){
		GUILayout.Label("Connection status: Disconnected");
		connectToIP = GUILayout.TextField(connectToIP, GUILayout.MinWidth(100));
		connectPort = parseInt(GUILayout.TextField(connectPort.ToString()));

		GUILayout.BeginVertical();
		if (GUILayout.Button ("Connect as client"))
		{
			Network.Connect(connectToIP, connectPort);
		}
		
		if (GUILayout.Button ("Start Server"))
		{

			var useNat = !Network.HavePublicAddress();
			Network.InitializeServer(32, connectPort,useNat);
		}
		GUILayout.EndVertical();
		
		
	}else{
		
		if (Network.peerType == NetworkPeerType.Connecting){
		
			GUILayout.Label("Connection status: Connecting");
			
		} else if (Network.peerType == NetworkPeerType.Client){
			
			GUILayout.Label("Connection status: Client!");
			GUILayout.Label("Ping to server: "+Network.GetAveragePing(  Network.connections[0] ));	
			
		} else if (Network.peerType == NetworkPeerType.Server){
			GUILayout.Label("Connection status: Server!");
			GUILayout.Label("Connections: "+Network.connections.length);
			if(Network.connections.length>=1){
				GUILayout.Label("Ping to first player: "+Network.GetAveragePing(  Network.connections[0] ));
			}			
			
		}

		if (GUILayout.Button ("Disconnect"))
		{
			Network.Disconnect(200);
		}
	}
}

But, It only makes servers with private IP (127.0.0.1), I want to make a server with Ip public, like: 190.226.xxx.117

So you can connect to the server from any PC.
How do I do this?
Thanks

The server is always all IP types your machine has.

The client will use what you specify, but public ip will often not work from within the lan and from outside you must have the portforwarding enabled or it won’t go anywhere

also the code seems to be for unity 2

Look into using the Unity Master server.

Register your game with the Unity Master Server, and initialize your server with useNat = true.

On the client, ping the master server for all of the games. When you want to connect… the only way I’ve succeeded was using Unity’s HostData structure, manually setting the useNat to be true, and then connecting via the GUID element of the HostData.

So…

Even though the server initializes with useNat = true, when you have the server you want to connect to you must use this:

pseudo-code

foreach(HostData host in serverList)
{
    host.useNat = true;
    Network.Connect(host.guid);
}

That is the only way I’ve gotten NAT punchthrough to succeed. Also note that when testing the NAT punchthrough, do NOT use the editor as a test client. You must build it to either a standalone or a webplayer build before it will successfully connect using the Host’s GUID.

If you try to from within the editor, there is a bug that says something like “Unhandled message 67, 70, 73 from XX.XX.XX.XX:XXXXX”, and if you retry the connection, the whole editor will crash!!!