Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Networking.Match;
  5.  
  6. public class JoinRoom : MonoBehaviour {
  7.  
  8.     LobbyManager lobbyManager;
  9.  
  10.     public GameObject hostGamePrefab;
  11.     public GameObject parentForHost;
  12.  
  13.     // Use this for initialization
  14.     void Start () {
  15.         lobbyManager = GameObject.FindGameObjectWithTag ("lobbyManager").GetComponent<LobbyManager> ();
  16.     }
  17.    
  18.     // Update is called once per frame
  19.     void Update () {
  20.        
  21.     }
  22.  
  23.     public void RefreshList(){
  24.         if (lobbyManager == null) {
  25.             lobbyManager = (LobbyManager)GameObject.FindGameObjectWithTag ("lobbyManager").GetComponent<LobbyManager> ();
  26.             // this line prints every time, meaning my lobbyManager is not being set
  27.             print ("lobby manager is null");
  28.             // this line prints as well and points me to the object it is supposed to be referencing
  29.             print (GameObject.FindGameObjectWithTag ("lobbyManager").GetComponent<LobbyManager> ());
  30.         }
  31.  
  32.         if (lobbyManager.matchMaker == null) {
  33.             lobbyManager.StartMatchMaker ();
  34.         }
  35.  
  36.         lobbyManager.matchMaker.ListMatches (0, 20, "", true, 0, 0, OnMatchList);
  37.  
  38.     }
  39.  
  40.     private void OnMatchList(bool success, string extendedInfo, List<MatchInfoSnapshot> matchList){
  41.         print ("JoinRoom:: OnMatchList");
  42.         if (!success) {
  43.             print ("Please refresh the list");
  44.         }
  45.         foreach (MatchInfoSnapshot match in matchList) {
  46.             GameObject listGO = Instantiate (hostGamePrefab);
  47.             listGO.transform.SetParent (parentForHost.transform);
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement