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 hammondt · Jun 12, 2017 at 06:30 AM · unity 5networkingphotonroom

Unity Photon Engine JoinOrCreateGame

From my application's standpoint a room should have 2 players. When searching for a game I don't really care what other player joins it, just that we both get into a room.

When I do this:

 PhotonNetwork.JoinOrCreateRoom ("RoomName", roomOptions, null);

The first two players that join get into the room appropriately but when a third or fourth player attempt to join (they should go into game 2) they both get an error saying room is full. Because the game with "RoomName" is full.

Additionally I can't really do a random number room name as all of the players end up in their own individual rooms for the most part.

What's the best way to create or join a game using Photon such that every 2 players go into their own room?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Ardaaytac · Jun 12, 2017 at 09:15 AM

Try using null rather than a specific string.You can use just PhotonNetwork.JoinRandomRoom() and if it fails than this method will be called. void OnPhotonRandomJoinFailed() { print("Joining to random room has failed!, Creating new room..."); PhotonNetwork.CreateRoom(null); }

 public void SpawnPlayer (GameManager.GameType gameType)
     {
 
         switch (gameType)
         {
             case GameManager.GameType.TwoVersusTwo:
                 playerCount = 4;
                 break;
             case GameManager.GameType.OneVersusOne:
                 playerCount = 2;
                 break;
             case GameManager.GameType.AgainstAI:
                 playerCount = 1;
                 break;
 
             default:
                 break;
         }
 
         StartCoroutine(LookForTotalPlayersInRoom(playerCount)); 
     }

code from my cancelled game. You can just use a coroutine to wait for start the game. For example player selected 1v1? Join a room and wait for another player,if player count == 2, than lock the room.

You can always lock with PhotonNetwork.room.IsOpen = false; ,

 IEnumerator LookForTotalPlayersInRoom(int playerCount)
     {
         yield return new WaitUntil(() => PhotonNetwork.playerList.Length == playerCount);//playerCount
 
         GameManager.instance.waitingForPlayerPanel.SetActive(false);
         //ROOM LOCKED
         PhotonNetwork.room.IsOpen = false;
         //ROOM LOCKED
         GameManager.instance.matchmakingPanel.SetActive(true);
 
         switch (playerCount)
         {
             case 4:
                 GameManager.instance.matchmakingPanelTexts[0].text = PhotonNetwork.playerList[0].NickName;
                 GameManager.instance.matchmakingPanelTexts[1].text = PhotonNetwork.playerList[1].NickName;
                 GameManager.instance.matchmakingPanelTexts[2].text = PhotonNetwork.playerList[2].NickName;
                 GameManager.instance.matchmakingPanelTexts[3].text = PhotonNetwork.playerList[3].NickName;
                 GameManager.instance.currentRoomTotalPlayers = 4;
                 StartCoroutine(Init2v2());
                 break;
             case 2:
                 GameManager.instance.matchmakingPanelTexts[0].text = PhotonNetwork.playerList[0].NickName;
                 GameManager.instance.matchmakingPanelTexts[2].text = PhotonNetwork.playerList[1].NickName;
                 GameManager.instance.currentRoomTotalPlayers = 2;
                 StartCoroutine(Init1v1());
                 break;
             case 1:
                 InitVSAI();
                 break;
             default:
                 break;
         }
     }


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
1

Answer by ChristianSimon · Jun 12, 2017 at 07:55 AM

Hi,

each client can do a PhotonNetwork.JoinRandomRoom(); first. This either lets the client join an available room or results in an OnPhotonRandomJoinFailed callback which you have to implement. When this callback is executed, the clients knows, that there is no room available and he can create a new room himself. For the room name he can for example use his Name, UserID, another (unique) value or even null.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Connect() to 'ns.exitgames.com' failed: System.Net.Sockets.SocketException: No such host is known 1 Answer

Instantiate player cards copy online at particular positions 0 Answers

Why doesn't this work 2 Answers

How to get all created rooms and join any one of them in PHOTON 2 Answers

UNet, how to create Internet game (like via PhotonNetwork) 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