I have a small script that at this point I only want it to see if a match is available, and if it is then join it. If not, then create one. I cant seem to get into a match that is already on. The script only creates a new match. I know i must be missing something relatively simple.
I narrowed it down a bit by letting one instance of the game start and create the match. Then i run a new instance in the editor with the NetworkManager HUD. From there i can find the match and join.
Here is my script. Any help is greatly appreciated. Thanks in advance.
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
using UnityEngine.Networking.Types;
using UnityEngine.Networking.Match;
using System.Collections.Generic;
public class NetworkPicker : NetworkBehaviour
{
public NetworkManager manager;
void Awake()
{
manager = GetComponent<NetworkManager>();
startConnection();
manager.matchMaker.ListMatches(0, 20, "", createMMMatch);
}
void startConnection()
{
if (!NetworkServer.active && !NetworkClient.active)
{
if (manager.matchMaker == null)
{
startMM();
Debug.Log("Match Maker Started");
}
}
}
void startMM()
{
if (manager.matchMaker == null)
{
manager.StartMatchMaker();
}
}
void createMMMatch(ListMatchResponse response)
{
if (response.success)
{
if (manager.matches == null)
{
manager.matchMaker.CreateMatch(manager.matchName, manager.matchSize, true, "", manager.OnMatchCreate);
Debug.Log("Match Created " + manager.matchSize);
}
}
else
{
joinMMMatch();
}
}
void joinMMMatch()
{
manager.matchMaker.JoinMatch(manager.matches[0].networkId, "", manager.OnMatchJoined);
Debug.Log("Match Joined!");
}
}