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 aidinz · May 04, 2016 at 03:06 PM · networking

How to detect number of players in a room?

Hi,

I'm making a 2-player game over the Internet.

1) How can first player create a room? 2) How can 2nd player see that room and join him? 3) no other player can join? 4) How can I know when to start the game? For this we need to know number of players in current room.

Thanks

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

3 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by correia55 · Feb 25, 2018 at 12:12 PM

As sugested by @FortisVenaliter, you should first follow some tutorials or read the manual. This should be enough to cover all of the questions you asked in the the description.

As for the other users who end up here because of the question in the title, you can get the number of players from the NetworkManager.

 NetworkManager nm = FindObjectOfType<NetworkManager>();
 nm.numPlayers
Comment
Add comment · Share
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
avatar image
0

Answer by FortisVenaliter · May 04, 2016 at 05:14 PM

You should really check out the Learn section of this site. There are 18 networking tutorials there that answer all of your questions.

Comment
Add comment · Show 2 · Share
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
avatar image aidinz · May 07, 2016 at 07:19 AM 0
Share

I've done those, but honestly they are towards beginners. What I want is intermediate tutorials to let me learn about Lobbies, game logic on server, etc.

avatar image Poon-Moon · Apr 09, 2019 at 07:21 PM 0
Share

Really unhelpful comment. There are 18 sub standard / no fit for purpose / non functional 'tutorials'. If you have such a distinct grasp on the subject, perhaps you could offer a real world solution?

avatar image
0

Answer by meat5000 · May 07, 2016 at 09:49 AM

Here's a simple implementation. Its ripped from a script I wrote so its not concise. When my players enter the game they are added to List. The Player Setup script on each player determines if the object is the local player or remote player and changes the tag to reflect this. So the server simply Finds the objects and adds them to a List, firstly so I can keep a good handle on each player and secondly, so I can count them. In this case "Player" is the local Client on the Host machine and PlayerRemote is every other connected player. I've not shown declarations but I'm sure you'll get the idea.

 @Server
 function ScanForPlayers()
 {
     yield WaitForSeconds(1);
     if(isServer)
     {
         this.playerList.Clear();
         
         var myPlayer = GameObject.FindWithTag("Player");
         this.playerList.Add(myPlayer);
         
         var myObject = GameObject.FindGameObjectsWithTag("PlayerRemote");
         for(var i=0;i<myObject.Length;i++)
         {
             this.playerList.Add(myObject[i]);
             yield;
         }
         
         yield;
         timer = 0; //Reset search timer after last search completes.
         playerNumbers = playerList.Count;
         
         if(playerNumbers > 0)
         {
             playersReady = true;
         }
         else { playersReady = false; }
         
         canScan = true;
     }
 }
Comment
Add comment · Share
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

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

6 People are following this question.

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

Related Questions

Unity networking tutorial? 6 Answers

PhotonNetwork.Instantiate is not "buffered" 0 Answers

[Edited]How To establish a mmo game By using Bluetooth 1 Answer

Bestpractice for receiving external commands 0 Answers

Why when I make a Networking first person game it controls the other person? 1 Answer


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