I have a pretty interesting problem. I’m currently working on a multiplayergame and I’ve used the default Unity Master Server. It went pretty well until yesterday. Everything worked fine but when I tested the game again, the OnMasterServerEvent wasn’t called anymore. I’ve tried to figure out why this problem appears but the only thing I’ve figured out was that the event gets called in some other classes.
Does anyhone have a solution for this problem? I mean it’s pretty strange that the code just stops working without any changes…
My Code:
public class NET_OnlineManager : MonoBehaviour {
void OnMasterServerEvent(MasterServerEvent msEvent)
{
if (msEvent == MasterServerEvent.HostListReceived)
{
if (!NET_ServerSetup.checkForEqualNames)
{
NET_Serverlist.hostList = MasterServer.PollHostList ();
GameObject.Find("Skripte").GetComponent<NET_Serverlist>().calculateButtonPositions ();
}
}
}
}
public class NET_Serverlist : MonoBehaviour {
public GameObject musterButton;
public static HostData[] hostList;
public void refreshServerlist()
{
MasterServer.ClearHostList ();
MasterServer.RequestHostList (NET_OnlineManager.GAMENAME);
}
public void calculateButtonPositions()
{
GameObject[] allButtons = GameObject.FindGameObjectsWithTag ("JoinButton");
foreach (GameObject jButton in allButtons)
Destroy (jButton);
for (int i = 0; i < hostList.Length; i++)
{
GameObject newButton = Instantiate (musterButton, musterButton.transform.position, musterButton.transform.rotation, musterButton.transform.parent) as GameObject;
newButton.transform.position = new Vector3 (newButton.transform.position.x, newButton.transform.position.y - (i * 20), newButton.transform.position.z);
newButton.GetComponent<Button> ().onClick.AddListener (delegate { NET_OnlineManager.ConnectToServer(hostList[i]); });
newButton.GetComponentInChildren<Text> ().text = hostList [i].gameName;
newButton.GetComponentInChildren<Text> ().enabled = true;
newButton.GetComponent<Button> ().enabled = true;
newButton.GetComponent<Image> ().enabled = true;
newButton.name = "Join Button " + (i+1);
newButton.tag = "JoinButton";
if (i == (hostList.Length - 1))
break;
}
}
}