Hello!
Not sure if this is the right place to post this, as I am trying to create my own GUI for the NetworkLobbyManager in Unity 5.4 Beta. Right now, I’m mostly having a hard time figuring out what code I need to start the MatchMaker Lobby. I’ve tried looking through documentation and through examples by others, but things are a mess since the Networking code has been simplified since 5.3. Here’s some code that I was trying out. I can’t seem to get any lobbies working. What am I missing? Is there somewhere other than the documentation that could provide me with more clear directions?
Thanks in advance for any help that you can provide.
Show Code
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
using System.Collections;
public class MainMenuBehavior : MonoBehaviour
{
public NetworkLobbyManager mgr;
public GameObject MainMenuPanel;
public GameObject CreateGamePanel;
public GameObject JoinGamePanel;
public GameObject SettingsPanel;
public GameObject CreditsPanel;
private string PlayerName;
private string MatchName;
private string MatchPassword;
public bool isLan = false;
void Awake()
{
mgr.StartMatchMaker();
}
/***
* Begin Button Network Functionality Code
***/
public void OnHostLAN()
{
isLan = true;
}
public void OnHostMatchMaker()
{
isLan = false;
}
// Creates A Lobby
public void OnCreateLobby()
{
if (isLan)
{
mgr.matchMaker.CreateMatch("Test Game LAN", 8, true, "", "public address", "private address", 0, 0, mgr.OnMatchCreate);
// TODO: Setup Connection To LAN Lobby
}
else
{
mgr.matchMaker.CreateMatch("Test Game Matched", 8, true, "", "", "", 0, 0, mgr.OnMatchCreate);
// TODO: Setup Connection To Non-LAN Lobby
}
}
// This Attempts to Connect To A Lobby
public void OnConnectToLobby()
{
}
// This Refreshes The List Of Lobbies
public void OnRefreshGames()
{
}
/***
* End Button Network Functionality Code
***/
/***
* Begin GUI Controller Code
***/
public void OnCreateMultiplayerMenu()
{
if (MainMenuPanel != null)
MainMenuPanel.SetActive(false);
if (CreateGamePanel != null)
CreateGamePanel.SetActive(true);
else
MainMenuPanel.SetActive(true);
if (JoinGamePanel != null)
JoinGamePanel.SetActive(false);
if (SettingsPanel != null)
SettingsPanel.SetActive(false);
if (CreditsPanel != null)
CreditsPanel.SetActive(false);
}
public void OnJoinMultiplayerMenu()
{
if (MainMenuPanel != null)
MainMenuPanel.SetActive(false);
if (CreateGamePanel != null)
CreateGamePanel.SetActive(false);
if (JoinGamePanel != null)
JoinGamePanel.SetActive(true);
else
MainMenuPanel.SetActive(true);
if (SettingsPanel != null)
SettingsPanel.SetActive(false);
if (CreditsPanel != null)
CreditsPanel.SetActive(false);
}
public void OnSettingsMenu()
{
if (MainMenuPanel != null)
MainMenuPanel.SetActive(false);
if (CreateGamePanel != null)
CreateGamePanel.SetActive(false);
if (JoinGamePanel != null)
JoinGamePanel.SetActive(false);
if (SettingsPanel != null)
SettingsPanel.SetActive(true);
else
MainMenuPanel.SetActive(true);
if (CreditsPanel != null)
CreditsPanel.SetActive(false);
}
public void OnCreditsMenu()
{
if (MainMenuPanel != null)
MainMenuPanel.SetActive(false);
if (CreateGamePanel != null)
CreateGamePanel.SetActive(false);
if (JoinGamePanel != null)
JoinGamePanel.SetActive(false);
if (SettingsPanel != null)
SettingsPanel.SetActive(false);
if (CreditsPanel != null)
CreditsPanel.SetActive(true);
else
MainMenuPanel.SetActive(true);
}
public void OnQuitGameMenu()
{
}
public void OnReturnToMainMenu()
{
mgr.StopMatchMaker();
if (CreateGamePanel != null)
CreateGamePanel.SetActive(false);
if (JoinGamePanel != null)
JoinGamePanel.SetActive(false);
if (SettingsPanel != null)
SettingsPanel.SetActive(false);
if (CreditsPanel != null)
CreditsPanel.SetActive(false);
if (MainMenuPanel != null)
MainMenuPanel.SetActive(true);
}
/***
* END GUI Controller Code
***/
}
EDIT: Updated the code.
EDIT #2: Here’s the error I’ve been getting when trying to create a lobby.
Show Error Message NetworkLobbyManager can’t accept new connection [hostId: -1 connectionId: 0 isReady: False channel count: 0], not in lobby and game already in progress.