- Home /
Question by
Harry_Harry · May 31, 2015 at 08:42 PM ·
multiplayeronlinemasterserverandoid
Problem with master server for android
I wanted to make a game for android with a lobby system where players are able to create a room and all other players have a list of all active games and can join a room they want. For this I used the master server from unity. The problem is that it only works when the two devices are coneccted with the same internet. When the two devices are not in the same internet, they can see all active rooms but are not able to connect.
Have anyone a idea what i need to change that it works?
using UnityEngine;
using System.Collections;
public class NetworkManager : MonoBehaviour {
string registeredGameName = "HarryGames_BattleQuest_Arena";
string gamename = "Battle Quest Arena";
bool isRefreshing = false;
float refreshRequestLength = 3.0f;
HostData[] hostData;
private void StartServer(){
Network.InitializeServer (5, 25002, false);
MasterServer.RegisterHost (registeredGameName, gamename);
}
void OnServerInitialized(){
Debug.Log ("Spiel eingerichtet");
}
void OnMasterServerEvent(MasterServerEvent masterServerEvent){
if (masterServerEvent == MasterServerEvent.RegistrationSucceeded){
Debug.Log ("Registriert");
}
}
public IEnumerator RefreshHostList(){
Debug.Log ("Refreshing...");
MasterServer.RequestHostList (registeredGameName);
float timeEnd = Time.time + refreshRequestLength;
while (Time.time < timeEnd) {
hostData = MasterServer.PollHostList();
yield return new WaitForEndOfFrame();
}
if (hostData.Length == null || hostData.Length == 0)
Debug.Log ("Keine Spiele gefunden");
}
public void OnGUI(){
if (Network.isClient || Network.isServer)
return;
gamename = GUI.TextField (new Rect (5, 5, 150, 50), gamename, 20);
if (GUI.Button (new Rect (5, 60, 150, 50), "Spiel einrichten")) {
StartServer ();
}
if (GUI.Button (new Rect (5, 115, 150, 50), "Liste aktualisieren")) {
StartCoroutine("RefreshHostList");
}
if (hostData != null) {
for(int i = 0; i < hostData.Length; i++){
if(GUI.Button(new Rect (175, 25 +(50 * i), 280, 50), hostData[i].gameName + ": " + hostData[i].connectedPlayers + " / " + hostData[i].playerLimit)){
Network.Connect(hostData[i]);
}
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Network multiplayer game - server and client at the same time 1 Answer
Whats wrong with this mutiplayer script 1 Answer
Online Multiplayer (Dedicated Hosting) 0 Answers
Turn Based Online Multiplayer help 1 Answer
Add one on local z axis 3 Answers