Hey I am currently working on making a room list for players to join. I have a bit of code that I combined together from multiple sources but is saying that object reference is not set to an instance of an object on the second line in the RefreshRoomListFunction. I do not know much about networking so I appreciate any help.
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine.Networking;
using UnityEngine.Networking.Match;
using UnityEngine;
public class joinGame : NetworkBehaviour {
List<GameObject> roomList = new List<GameObject>();
private NetworkManager networkManager;
[SerializeField]
private GameObject roomListItemPrefab;
[SerializeField]
private Transform roomListParent;
// Use this for initialization
void Start () {
networkManager = GetComponent<NetworkManager>();
RefreshRoomList ();
}
// Update is called once per frame
void Update () {
}
public void RefreshRoomList () {
ClearRoomList ();
networkManager.matchMaker.ListMatches (0, 20, "", true, 0, 0, networkManager.OnMatchList);
}
public void OnMatchList (bool success, string extendedInfo, List<MatchInfoSnapshot> matches) {
foreach (var match in networkManager.matches) {
GameObject _roomlistItemGO = Instantiate (roomListItemPrefab);
_roomlistItemGO.transform.SetParent (roomListParent);
roomList.Add (_roomlistItemGO);
}
}
void ClearRoomList () {
for (int i = 0; i < roomList.Count; i++) {
Destroy (roomList *);*
-
}*
-
roomList.Clear ();*
- }*
}