Simple network game.

Hello, I’m pretty new to Unity a friend got me to try it, as i do a lot work in VB.
after playing about and getting used to it. I then saw that Unity could do networking.
and i could make a game that me and my friend could play together

After doing a look about and talking with my friend i found this tutorial by a website
CGCookie.com Tutorial found here
after running thought the tutorial i got the game to work on my local system on a laptop and on my PC
but my friend could not connect he could see that i was hosting a server from his game client
(MasterServer.RegisterHost and MasterServer.PollHostList) but could not join
i was hoping that hamachi would work as i don’t really want to open my router to the world

the networking code i used was this

var playerPrefab:GameObject;
var spawnObject:Transform;
var gameName:String = "MytestNetworkgame";

private var refreshing:boolean;
private var hostData:HostData[];

private var btnX:float;
private var btnY:float;
private var btnW:float;
private var btnH:float;


function Start(){
	btnX = Screen.width * 0.05;
	btnY = Screen.height * 0.05;
	btnW = Screen.width * 0.12;
	btnH = Screen.width * 0.12;
}

function startServer(){
	Network.InitializeServer(32,25001, !Network.HavePublicAddress);
	MasterServer.RegisterHost(gameName, "test_game_1", "This is just a test of networks");
}

function refreshHostList(){
	MasterServer.RequestHostList(gameName);
	refreshing = true;
}

function Update(){
	if(refreshing){
		if(MasterServer.PollHostList().Length > 0){
			refreshing = false;
				Debug.Log("Server Found : " + MasterServer.PollHostList().Length);
			hostData = MasterServer.PollHostList();
		}
	}
}

function spawnPlayer(){
	Network.Instantiate(playerPrefab, spawnObject.position, Quaternion.identity, 0);
}

//Messages
function OnServerInitialized(){
	Debug.Log("Server Initialized");
	spawnPlayer();
}

function OnConnectedToServer(){
	spawnPlayer();
}

function OnMasterServerEvent(mse:MasterServerEvent){
	if(mse == MasterServerEvent.RegistrationSucceeded){
		Debug.Log("Server Registration Succeeded");
	}
}
//GUI
function OnGUI(){

	if(!Network.isClient  !Network.isServer){

		if(GUI.Button(Rect(btnX, btnY, btnW, btnH), "Start Server")){
			Debug.Log("Starting Server");	
			startServer();
		}
		if(GUI.Button(Rect(btnX, btnY * 1.2 + btnH, btnW, btnH), "Refresh Host")){
			Debug.Log("Refreshing");
			refreshHostList();	
		}
		if(hostData){
			for(var i:int = 0; i<hostData.length; i++){
				if(GUI.Button(Rect(btnX * 1.5 + btnW, btnY*1.2 + (btnH * i), btnW*3, btnH*0.5), hostData[i].gameName)){
					Network.Connect(hostData[i]);
			}
		}	
	}
	}
}

Am i doing something wrong or could it just not work on hamachi ??

and is there any other good simple networking tutorials out there that anyone can link me

thanks a bunch if you can help.
Sam :).

I used the same tutorial and got it to work by forwarding ports on my router. However, when I tried this on my laptop I had the same problem as you, and changing the local IP in the router also didn’t work.

Port forwarding really isn’t an option for me as i don’t have access to it

You might consider using Photon Unity Networking http://www.exitgames.com/

This way you don’t have to forward ports, your server runs in a cloud and it pretty much works like Unity networking.

Hmm, lol what else is there besides Photon? We can get LAN connection working fine, but there has to be another way to connect VIA Hamachi or something of it.

If it direct IP connection works on LAN, no reason for Hamachi to not work… But getting stuff to work through the internet directly is always more complicated (which is why Hamachi exists, really, to save you the trouble when using applications that would otherwise give you a hard time). Of course, in the end, if you want your game to be playable by the masses, it needs to work without Hamachi…

We honestly just want it to be able so we can connect to each other. Shlom0z and I will never really be able to use Local connection, and it’s great that that works but there has got to be a quicker fix