I have made a simple working multiplayer game using M50’s (Marisa Clardy - YouTube) multiplayer and network player tutorial, and replaced the ball in the tutorial with the standart construction_worker I added the if(networkView.ismine) rule to the movement controller and inside my home-network the game works perfect. But when I try to connect outside my home-network over internet or over hamachi, it does not work. I don’t get any error, if I type in anything other than my local ip it just won’t do anything. this is my multiplayer script:
using UnityEngine;
using System.Collections;
using System;
public class MPBase : MonoBehaviour {
public string connectToIp = "my ip";
public int connectPort = 26656;
public bool useNAT = false;
public string ipaddress = "";
public string port = "";
string playerName = "<NAME ME>";
void OnGUI()
{
if(Network.peerType == NetworkPeerType.Disconnected)
{
if(GUILayout.Button("Connect"))
{
if(playerName != "<NAME ME>")
{
Network.Connect(connectToIp, connectPort);
PlayerPrefs.SetString("playerName", playerName);
}
}
if(GUILayout.Button("Start Server"))
{
if(playerName != "<NAME ME>")
{
Network.InitializeServer(32, connectPort, useNAT);
foreach (GameObject go in FindObjectsOfType(typeof(GameObject)))
{
go.SendMessage("OnNetworkLoadedLevel", SendMessageOptions.DontRequireReceiver);
}
PlayerPrefs.SetString("playerName", playerName);
}
}
playerName = GUILayout.TextField(playerName);
connectToIp = GUILayout.TextField(connectToIp);
connectPort = Convert.ToInt32(GUILayout.TextField(connectPort.ToString()));
}
else
{
if(Network.peerType == NetworkPeerType.Connecting) GUILayout.Label("Connect 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 Server: " + Network.GetAveragePing(Network.connections[0]));
}
if (GUILayout.Button("Disconnect"))
Network.Disconnect(200);
ipaddress = Network.player.ipAddress;
port = Network.player.port.ToString();
GUILayout.Label("IP Address: " + ipaddress + ":" + port);
}
}
void OnConnectedToServer()
{
foreach (GameObject go in FindObjectsOfType(typeof(GameObject)))
{
go.SendMessage("OnNetworkLoadedLevel", SendMessageOptions.DontRequireReceiver);
}
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
All I want is to make it work over internet OR over hamachi, and by the way YES I have portforwarded in my router and in my firewall that’s not the issue. I would greatly appreciate any help (If you think my English is bad, you are right I’m Dutch and 15 years old).