Problem Joining Room

Options
Hi, im trying to make a simple Code to Join Two players in the same Room, but i cant make it work.
The first player is supposed to create a room because there is no rooms created and the second player should join, but it does not detect that there is any created room and the second player creates other room.

I really dont know what im doing wrong, I tried whit the example scenes from Phuton and I have the same issue, cant find other players or rooms.

Thanks alot. I'm using Photon 2.15 and Unity 2018.3.5.
using Photon.Pun;
using Photon.Realtime;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PhotonLobby : MonoBehaviourPunCallbacks
{
    public static PhotonLobby lobby;

    public GameObject battleButton;
    public GameObject cancelButton;

    public string userId; //Nou

    private void Awake()
    {
        lobby = this;
        
        userId = "" + Random.Range(-1000000, 1000000);//Nou
    }

    void Start()
    {
        PhotonNetwork.AuthValues = new AuthenticationValues(userId);//Nou
        PhotonNetwork.ConnectUsingSettings();
    }

     public override void OnConnectedToMaster()
     {
         Debug.Log("Player has connectet to the Photon Master server");
        PhotonNetwork.AutomaticallySyncScene = true; // Nou
         battleButton.SetActive(true);
     }

     public void OnBattleButtonClicked()
     {
         Debug.Log("Battle Button was click");
         battleButton.SetActive(false);
         cancelButton.SetActive(true);
         PhotonNetwork.JoinRandomRoom();
     }

     public override void OnJoinRandomFailed(short returnCode, string message)
     {
         Debug.Log("Tried to join a random game  but failed. There must be open games available");
         CreateRoom();
     }

     void CreateRoom()
     {
         Debug.Log("Tryign to create a new Room");
         int randomRoomName = Random.Range(0, 10000);
         RoomOptions roomOps = new RoomOptions() { IsVisible = true, IsOpen = true, MaxPlayers = 10 };
       // RoomOptions roomOps = new RoomOptions() { IsVisible = true, IsOpen = true, MaxPlayers = (byte)MultiplayerSetting.multiplayerSetting.maxPLayers };
        PhotonNetwork.CreateRoom("Room" + randomRoomName, roomOps);
     }

     public override void OnJoinedRoom()
     {
         Debug.Log("We are now in a room");
     }

     public override void OnCreateRoomFailed(short returnCode, string message)
     {
         Debug.Log("Triedn to create a new room but failed, there must already be whit the same name");
         CreateRoom();
     }

     public void OnCancelButtonClicked()
     {
         cancelButton.SetActive(false);
         battleButton.SetActive(true);
         PhotonNetwork.LeaveRoom();
    }
}

Best Answer

  • Xtrem1714
    Xtrem1714
    Answer ✓
    Options
    Ok, I tried uploading Photon but didnt worked so I deleted all Photon folders and reinstalled it other time. Finally works.

Answers

  • Xtrem1714
    Xtrem1714
    Answer ✓
    Options
    Ok, I tried uploading Photon but didnt worked so I deleted all Photon folders and reinstalled it other time. Finally works.