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 :).