Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by GamerBoxStudios · Apr 16, 2018 at 12:31 PM · multiplayer-networking

UnityNetworking fails to list matches..

Hey Unity Devs! So, I am making a Quizz multiplayer game in which 2 players select a category and they shall start a match, the problem is that I couldn't do that using unity networking. here is my code, what I am trying to achieve is:

I call the FindMatch() Function when ever the player selects a category.

try to find a match whenever a player selects a category looking for that categoryRoom. if the room wasn't there, then the player starts a room for 15 seconds then if no one showed up. they will play against bots. if hey found a game that is not full they should join. in my code, it just creates the room on each client..

here is my code:

 using UnityEngine;
 using UnityEngine.Networking;
 using UnityEngine.Networking.Match;
 using System.Collections.Generic;
 
 
 public class MatchManager : NetworkBehaviour{
 
     public static PlayerScript player;
 
     public static MatchManager Instance;
 
     public MatchInfo currentMatch;
 
     public static int status = 0;
 
     public string categoryToFind;
 
 
     private void Awake()
     {
         Instance = this;
         NetworkManager.singleton.StartMatchMaker();
     }
 
     public void CreateInternetMatch(string matchName)
     {
         NetworkManager.singleton.matchMaker.CreateMatch(matchName, 2, true, "", "", "", 0, 0, OnInternetMatchCreate);
     }
 
     private void OnInternetMatchCreate(bool success, string extendedInfo, MatchInfo matchInfo)
     {
         if (success)
         {
             Debug.Log("Create match succeeded");
             MatchInfo hostInfo = matchInfo;
             NetworkServer.Listen(hostInfo, 9000);
             NetworkManager.singleton.StartHost(hostInfo);
             currentMatch = matchInfo;
         }
         else
         {
             Debug.LogError("Create match failed");
         }
     }
 
 
     public void FindInternetMatch(string matchName)
     {
         categoryToFind = matchName;
         NetworkManager.singleton.matchMaker.ListMatches(0, 10, matchName, true, 0, 0, OnInternetMatchList);
     }
 
     private void OnInternetMatchList(bool success, string extendedInfo, List<MatchInfoSnapshot> matches)
     {
         if (success)
         {
             if (matches.Count != 0)
             {
                 foreach (MatchInfoSnapshot match in matches)
                 {
                     Debug.Log(match.currentSize);
                     if (match.currentSize < match.maxSize)
                     {
                         Debug.Log(match.name + " is available");
                         NetworkManager.singleton.matchMaker.JoinMatch(match.networkId, "", "", "", 0, 0, OnJoinInternetMatch);
                         return;
                     }
                 }
             }
             else
             {
                 CreateInternetMatch(categoryToFind);
             }
         }
         else
         {
             Debug.LogError("Couldn't connect to match maker");
         }
     }
 
     //this method is called when your request to join a match is returned
     private void OnJoinInternetMatch(bool success, string extendedInfo, MatchInfo matchInfo)
     {
         if (success)
         {
             Debug.Log("Able to join a match");
 
             MatchInfo hostInfo = matchInfo;
             NetworkManager.singleton.StartClient(hostInfo);
             currentMatch = matchInfo;
         }
         else
         {
             Debug.LogError("Join match failed");
         }
     }
 
     int counter = 0;
     public override void OnStartClient()
     {
         counter++;
         base.OnStartClient();
         Debug.Log("Client " + counter + " Started");
         if(counter == 2)
         {
             CmdStartMatch();
         }
     }
 
     public override void OnStartServer()
     {
         base.OnStartServer();
         Debug.Log("Server Started");
     }
     public override void OnStartLocalPlayer()
     {
         base.OnStartLocalPlayer();
         Debug.Log("LocalPlayerConnected");
     }
 
     public void StopConnection()
     {
         NetworkManager.singleton.matchMaker.DestroyMatch(currentMatch.networkId, 0, OnMatchDestroy);
     }
 
     private void OnMatchDestroy(bool success, string extdInfo)
     {
         if (success)
             Debug.Log("Match Destroyed");
         else
             Debug.LogError("Match not destroyed");
     }
     [Command]
     public void CmdStartMatch()
     {
         RpcStartMatch();
         Debug.Log("StartMatch_ServerCommand");
     }
 
     [ClientRpc]
     public void RpcStartMatch()
     {
         Debug.Log("Start Match!");
         QuizzGame.isBot = false;
         UiManager.Instance.ShowQuizzScreenOnly();
         CategoryUI.joinedAmatch = true;
         QuizzGame.Instance.quizzStarted = true;
     }
 }
 


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

78 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Getting error when making a chat system 0 Answers

Question on Development Priorities. 0 Answers

NetworkManager.OnServerDisconnect not being called 2 Answers

Unity's LLAPI for Raspberry Pi Server? 0 Answers

Random Map doesn't want spawn in Clients 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges