Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to Join Random Room?

Discussion in 'Multiplayer' started by Deleted User, Jul 1, 2017.

  1. Deleted User

    Deleted User

    Guest

    I've gotten the basic unet setup to work with the NetworkManager and NetworkManagerHUD. Now I need some help figuring out how to create a script that will search for rooms with empty slots. If it finds one, it should join it. If not, create a new match. How can I do this? Thanks in advance.
     
    Menzle likes this.
  2. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Using Unitys matchmaker?
     
  3. Deleted User

    Deleted User

    Guest

    Using Unity's HLAPI as described in the manuel. I want it to find a game when I press a button.
     
  4. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Yes, you are using Unitys High Level API for Networking? But what matchmaker are you using? Unitys? If so, I would look into retrieving a list of matches. Generate a random number between 0 and the length. And then join the match with the index of your random number
     
  5. Deleted User

    Deleted User

    Guest

    Yes I am using Unity's matchmaker. This sounds like a solution that could work. What exactly would the script look like? I don't have a lot of experience with C# yet…
     
  6. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Code (CSharp):
    1. MatchListClass[] matches = GetMatches();
    2. int index = Random.Range(0, matches.Length);
    3. NetworkManager.singleton.StartClient(matches[index]);
    Something like that.
     
  7. Deleted User

    Deleted User

    Guest

    After looking into this, it didn't work. I tried tweaking some things to fix errors to no avail. I think it could work if I used NetworkMatch.JoinMatch(); but had some way to set a variable for the unetId. The only problem is, I can't figure out how to get the unetId of a random game that is not full.
     
  8. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    The code I provided is not functional. I was just showing how it would be done. I don't know the exact class names for the Matchmaker
     
  9. LuxindraGaming

    LuxindraGaming

    Joined:
    Sep 2, 2020
    Posts:
    4
    hi, @vis2k @Tornadoally @tomweiland @TwoTen @PartyBoat I'm new in multiplayer game with mirror networking and I'm still learning. I want one help from you guys, how I join random room and if there is no room available then create its own room. is there any way to do that. if you have any solution with the script please provide.

    Like, I'm making a simple board game and in first scene there will be one button says Play Button. Using this play button player will find random room and if room available then join else create its own room.
    please give a script if you have any.

    Thanks in advance.