[Fixed] Multiplayer – Can’t create a room!!!

Updated on June 24, 2018 in [A] Multiplayer
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
1 on June 15, 2018

Hello everyone,

I don’t know how, I didn’t done anything with my code or anything else, but now I don’t have this problem! So you can read my post, maybe you have the same problem, then copy my code, but I don’t have the problem anymore. But if you have a suggestion to fix or clear my code (I am sure that I have wrong things or not clear things in my code), I’d be happy and grateful when you say that! 🙂

PLEASE HELP ME!!!! I have a really BIG PROBLEM! I CAN’T CREATE Rooms, but my script is just like the script of Brackeys, no Errors! Actually I don’t know where exactly the problem is! I’ve written a Debug.Log when I create a room and it doesn’t stand in the Console. I write my Host, Join and RoomListItem script down, so somebody can help me! Look at my code and I’ve referenced everything, so this can’t be the problem! I don’t get any Errors! Please help me as fast as you can! I’ll be very GRATEFUL, when somebody helps me!!! Thanks already in advance.

 

[HostGame]

[

 

using UnityEngine;
using UnityEngine.Networking;

 

public class HostGame : MonoBehaviour
{

 

[SerializeField]
private uint roomSize = 6;

 

private string roomName;

 

private NetworkManager networkManager;

 

void Start()
{
networkManager = NetworkManager.singleton;
if (networkManager.matchMaker == null)
{
networkManager.StartMatchMaker();
}
}

 

public void SetRoomName(string _name)
{
roomName = _name;
}

 

public void CreateRoom()
{
if (roomName != “” && roomName != null)
{
Debug.Log(“Creating Room: ” + roomName + ” with room for ” + roomSize + ” players.”);
networkManager.matchMaker.CreateMatch(roomName, roomSize, true, “”, “”, “”, 0, 0, networkManager.OnMatchCreate);
}
}

 

}

 

]

 

[JoinGame]

[

 

using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
using UnityEngine.Networking;
using UnityEngine.Networking.Match;

 

public class JoinGame : MonoBehaviour {

 

List roomList = new List();

 

[SerializeField]
private Text status;

 

[SerializeField]
private GameObject roomListItemPrefab;

 

[SerializeField]
private Transform roomListParent;

 

private NetworkManager networkManager;

 

void Start ()
{
networkManager = NetworkManager.singleton;
if (networkManager.matchMaker == null)
{
Debug.Log(“No matchmaking!”);
networkManager.StartMatchMaker();
}

 

RereshRoomList();
}

 

public void RefreshRoomList()
{
ClearRoomList();

 

if (networkManager.matchMaker == null)
{
Debug.Log(“No matchmaking!”);
networkManager.StartMatchMaker();
}

 

networkManager.matchMaker.ListMatches(0, 20, “”, true, 0, 0, OnMatchList);
status.text = “Loading…”;
}

 

public void OnMatchList (bool success, string extendedInfo, List matchList)
{
status.text = “”;

 

if (!success || matchList == null)
{
status.text = “Couldn’t get room list.”;
return;
}

 

foreach (MatchInfoSnapshot match in matchList)
{
GameObject _roomListItemGO = Instantiate(roomListItemPrefab);
_roomListItemGO.transform.SetParent(roomListParent);

 

RoomListItem _roomListItem = _roomListItemGO.GetComponent();
if (_roomListItem != null)
{
_roomListItem.Setup(match, JoinRoom);
}

 

roomList.Add(_roomListItemGO);
}

 

if (roomList.Count == 0)
{
status.text = “No rooms at the moment.”;
}
}

 

void ClearRoomList()
{
for (int i = 0; i < roomList.Count; i++)
{
Destroy(roomList[i]);
}

 

roomList.Clear();
}

 

public void JoinRoom(MatchInfoSnapshot _match)
{
networkManager.matchMaker.JoinMatch(_match.networkId, “”, “”, “”, 0, 0, networkManager.OnMatchJoined);
ClearRoomList();
status.text = “Joining…”;
}
}

 

]

 

[RoomListItem]

[

 

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking.Match;

 

public class RoomListItem : MonoBehaviour
{

 

public delegate void JoinRoomDelegate(MatchInfoSnapshot _match);
private JoinRoomDelegate joinRoomCallback;

 

[SerializeField]
private Text roomNameText;

 

private MatchInfoSnapshot match;

 

public void Setup(MatchInfoSnapshot _match, JoinRoomDelegate _joinRoomCallback)
{
match = _match;
joinRoomCallback = _joinRoomCallback;

 

roomNameText.text = match.name + ” (” + match.currentSize + “/” + match.maxSize + “)”;
}

 

public void JoinRoom()
{
joinRoomCallback.Invoke(match);
}

 

}

 

 

 

]

  • Liked by
  • FazEBook
Reply
0 on June 24, 2018

Hello everyone, 

I don’t know how, I didn’t done anything with my code or anything else, but now I don’t have this problem! So you can read my post, maybe you have the same problem, then copy my code, but I don’t have the problem anymore. But if you have a suggestion to fix or clear my code (I am sure that I have wrong things or not clear things in my code), I’d be happy and grateful when you say that! 🙂

  • Liked by
Reply
Cancel