Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

PUN: How can i create or join a PUN room when requested?

Discussion in 'Multiplayer' started by fantekvelik, Jun 14, 2022.

  1. fantekvelik

    fantekvelik

    Joined:
    Sep 27, 2020
    Posts:
    5
    Hi all! So I am making a multiplayer game in PUN v2 (obviously) and I need some help. Basically what I want to do is when the player is in the main menu scene he can: join a room selected from a dropdown; speaking of: how could I draw all the rooms that PUN finds on a dropdown list and then when player selects one and then clicks join, it joins that specific room. Then he can also create a room. Where it would put him on a UI view where he needs to specify the max amount of players he wants, and a room name that will be displayed on the dropdown. I am quite new and I know that I should be doing simpler thing but I already did and I don't like the little amount of choice that player has when using JoinRandomOrCreateRoom. So yeah. I appreciate any answer and thanks to those that are willing to help me. Good Day!
     
  2. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    195
    If you join a lobby you can get all the rooms in the lobby. So you would then want to make a UI prefab that has some text and a button. For each room you instantiate that prefab with the info you want to show the user and make the button join that specific room. Parent those to a scrollable list, for example, to allow the user to browse through all available rooms and join one.

    For creating a room just have some input fields with the necessary info, player count, room name, etc. Then have a button that creates a room using the values in those fields.
     
    tobiass likes this.
  3. fantekvelik

    fantekvelik

    Joined:
    Sep 27, 2020
    Posts:
    5
    Ok I see. I was also thinking of a system like this. but for the server list couldn't you just create a string array to which you write the server names and then also link the specific string name to a specific room? But I also need some code reference mainly how to make the JoinRoom void execute only when pressing a button. Since as far as I know it executes it automaticly. I could be wrong. And thanks for the help
     
  4. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    195
    There are numerous ways you could do this, my example was just one. I'm not sure what you mean by "it executes automatically"? You would have some code that creates your prefab for each room, and that code would set the button click event to join that specific room. So then when the user clicks that button they join that room. And you'd want to hide all the other buttons at that point so they either join the room or fail and you reload the list, that way they don't get clicky and try to join multiple rooms.
     
  5. fantekvelik

    fantekvelik

    Joined:
    Sep 27, 2020
    Posts:
    5
    Hello! For everyone that may need help I found this great totoriall:
    .
    Good Luck with your project!