- Home /
Question by
Trevdevs · Mar 27, 2017 at 11:11 PM ·
c#networkingmultiplayer-networkingmultiplayer networkingnetwork instantiate
NetworkMatch creating match not being found when doing ListMatches
NetworkMatch.count still returns zero after I refresh the list after creating the match does it not get instantly added is there something I'm missing.
This is my very first time attempting a form of multiplayer so sorry if the script is bad. Line 49 to 64
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Networking.Match;
using UnityEngine.Networking.Types;
using UnityEngine.UI;
public class NetworkController : MonoBehaviour {
public NetworkManager man;
NetworkMatch networkMatch;
string lobbyName;
Toggle isPrivate;
public VerticalLayoutGroup serverSlots;
[SerializeField]
private GameObject lobbyPrefab;
void Awake()
{
networkMatch = man.gameObject.AddComponent<NetworkMatch>();
}
void Start()
{
networkMatch.ListMatches(0, 10, "", true, 0, 0, OnMatchList);
}
void Update()
{
if(Input.GetKeyDown(KeyCode.R))
{
RefreshLobbyList();
}
}
void RefreshLobbyList()
{
networkMatch.ListMatches(0, 10, "", true, 0, 0, OnMatchList);
}
void OnMatchList(bool foundMatches, string extendedInfo, List<MatchInfoSnapshot> matches)
{
if(foundMatches)
{
Debug.Log(matches.Count); //<--- Returns zero after I create a match
foreach (MatchInfoSnapshot match in matches)
{
GameObject lobby = Instantiate(lobbyPrefab, serverSlots.transform) as GameObject;
lobby.GetComponentInChildren<Text>().text = match.name;
}
}
else
{
Debug.Log(extendedInfo);
}
}
void HostLobby() //This runs from a UI Button
{
networkMatch.CreateMatch(lobbyName, 4, true, "", "", "", 0, 0, OnMatchCreate); //Match Creation Here
}
void OnMatchCreate(bool created, string extendedInfo, MatchInfo matchInfo)
{
if(created)
{
Debug.Log("Match Created");
//man.StartHost(matchInfo);
}
else
{
Debug.Log(extendedInfo);
Debug.Log("Matched Creation Failed");
}
}
void JoinLobby(NetworkID id)
{
networkMatch.JoinMatch(id, "", "", "", 0, 0, OnMatchJoined);
}
void OnMatchJoined(bool joinedMatch, string extendedInfo, MatchInfo matchInfo)
{
MatchInfo hostInfo = matchInfo;
//man.StartClient(hostInfo);
}
}
Comment
Your answer
Follow this Question
Related Questions
Player object on host can interact with objects, client players cannot. 0 Answers
Clients can't spawn bullets, but the server does 1 Answer
UNET Multiplayer Lobby not creating an instance of the lobby player 1 Answer
Loading spawned prefabs upon connecting to server? 1 Answer
Mirror: How to have the player object active before connecting to spawn it. 1 Answer