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 zak666 · Nov 26, 2017 at 06:20 AM · photoncountroomplayers

PHOTON "Count Of players" not working for Client 1?

Hey gang, I have a small problem with my game, everything seems to work find except with Client 1. the first client to load stays on "Waiting for Players to Join" when the Second Client connects Client to Proceeds to show the "Launch" Button, Client 1 should also show the "LAUNCH" button when their are 2 or more Players in "Count of Players". so plays can only start the game when both players are connected have I missed a step:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using Photon;
 public class ConnectOnline : Photon.MonoBehaviour {
 
     public GameObject EarthMap;
     public GameObject MarsMap;
     public GameObject LaunchButton;
     public float MapSelect;
 
 
 
     public virtual void Start()
     {
         PhotonNetwork.autoJoinLobby = true;    // we join randomly. always. no need to join a lobby to get the list of rooms.
         PhotonNetwork.ConnectUsingSettings("0.1");
 
 
     }
 
     public  void OnConnectedToMaster()
     {
         Debug.Log("OnConnectedToMaster() was called by PUN. Now this client is connected and could join a room. Calling: PhotonNetwork.JoinRandomRoom();");
         PhotonNetwork.JoinRandomRoom();
     }
 
     public  void OnJoinedLobby()
     {
         Debug.Log("OnJoinedLobby(). This client is connected and does get a room-list, which gets stored as PhotonNetwork.GetRoomList(). This script now calls: PhotonNetwork.JoinRandomRoom();");
         PhotonNetwork.JoinRandomRoom();
         RoomOptions roomOptions = new RoomOptions () { isVisible = true, maxPlayers = 2 };
         PhotonNetwork.JoinOrCreateRoom ("roomName", roomOptions, TypedLobby.Default);
     }
 
     public  void OnPhotonRandomJoinFailed()
     {
         RoomOptions roomOptions = new RoomOptions () { isVisible = true, maxPlayers = 2 };
         Debug.Log("OnPhotonRandomJoinFailed() was called by PUN. No random room available, so we create one. Calling: PhotonNetwork.CreateRoom(null, new RoomOptions() {maxPlayers = 4}, null);");
         PhotonNetwork.JoinOrCreateRoom ("roomName", roomOptions, TypedLobby.Default);
     }
 
 
     public void Update() {
 
         if(PhotonNetwork.countOfPlayers == 2){
             LaunchButton.SetActive (true);
 
         }
 
 
         if (PhotonNetwork.isMasterClient == true && PhotonNetwork.countOfPlayers == 2) {
             MapSelect = 0;
             MapSelect = Random.Range (0, 6);
 
             if (MapSelect > 0 && MapSelect < 3.1) {
                 EarthMap.SetActive (true);
                 photonView.RPC ("FireOtherTeam1", PhotonTargets.OthersBuffered);
 
             }
 
             if (MapSelect > 3.1 && MapSelect < 6) {
                 MarsMap.SetActive (true);
                 photonView.RPC ("FireOtherTeam2", PhotonTargets.OthersBuffered);
 
             }
         }
     }
 
 
 
     [PunRPC]
     void FireOtherTeam2 (){
         EarthMap.SetActive (true);
 
     }
 
     [PunRPC]
     void FireOtherTeam1 (){
         MarsMap.SetActive (true);
 
     }
 
 
 
 
 }

![alt text][1]

screen-shot-2017-11-26-at-51607-pm.png (223.4 kB)
screen-shot-2017-11-26-at-51607-pm.png (223.4 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ChristianSimon · Nov 28, 2017 at 09:58 AM

Hi,

there is a problem with your OnJoinedLobby callback function. In this function you are calling JoinRandomRoom and JoinOrCreateRoom which doesn't work the way you want. Try using either one of these. You can for example use JoinRandomRoom and additionally implement the OnPhotonRandomJoinFailed(object[] codeAndMsg) { // codeAndMsg[0] is short ErrorCode. codeAndMsg[1] is string debug msg. } callback to get notified if there is no random room available. In this case you can also use this callback to call JoinOrCreateRoom or just CreateRoom in order to create and join a new room.

To get the number of players in your room you can use PhotonNetwork.room.PlayerCount instead of countOfPlayers. Before checking PhotonNetwork.room.PlayerCount please make sure that the client actually is inside a room by using the PhotonNetwork.inRoom condition.

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

77 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

Related Questions

UNet, how to create Internet game (like via PhotonNetwork) 0 Answers

Why does Photon find a room so quick! 1 Answer

photon marco polo tutorial issue with "peercreated" 1 Answer

Need help with joining a room in photon? 1 Answer

GUI issues 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