How to Join to your friend's room

Hi guys, I want to join to my friend room, first I join to a lobby and create a room(of course I connect to photon first and to playfab) then when I click in my friend, I check if photon is connected and join his room as you can see here:
if (PhotonNetwork.IsConnected)
{
Debug.Log($"Joining Friend's Room: {roomName}");
PhotonNetwork.JoinRoom(roomName);
}
else
Debug.Log("not connected so can't join");
then I want to see if he joined so I have playerlisting.

using Photon.Pun;
using Photon.Realtime;
using System.Collections.Generic;
using UnityEngine;

public class PlayerListing : MonoBehaviourPunCallbacks
{
[SerializeField]
public Transform content;
[SerializeField]
public UiFriendRoom _uifriendroom;

private List<UiFriendRoom> _Uifriend = new List<UiFriendRoom>();

private void AddPlayerListing(Player player)
{
UiFriendRoom uIFriend = Instantiate(_uifriendroom, content);
if (uIFriend != null)
{
uIFriend.SetPlayerInfo(player);
_Uifriend.Add(uIFriend);
Debug.Log("OnPlayerEnteredRoom was called");
}
}

private void GetCurrentRoomPlayers()
{
Debug.Log("Trying to get the current room's players");
Debug.Log($"Are we in a room though: {PhotonNetwork.InRoom}");
if (!PhotonNetwork.InRoom) return;
foreach (KeyValuePair<int, Player> PlayerInfo in PhotonNetwork.CurrentRoom.Players)
{
Debug.Log("OnPlayerEnteredRoom was called");
AddPlayerListing(PlayerInfo.Value);
}
}
public override void OnPlayerEnteredRoom(Player newPlayer)
{
AddPlayerListing(newPlayer);
Debug.Log("OnPlayerEnteredRoom was called");

}
public override void OnJoinedRoom()
{
GetCurrentRoomPlayers();
}



public override void OnPlayerLeftRoom(Player otherPlayer)
{
int index = _Uifriend.FindIndex(x => x.Player == otherPlayer);
if (index != -1)
{
Destroy(_Uifriend[index].gameObject);
_Uifriend.RemoveAt(index);
Debug.Log("why did you left the room?");
}
}



public override void OnLeftRoom()
{
Debug.Log("left Room");

}
}
I do not know if the problem is with the joining rooms or with the PlayerListing, it doesn't show the friend's in the player listing. and I have this error when I press mu friend button(to join him) : JoinRoomfailed. client is on game server(Must be master server for matchmaking) and ready.wait for callback: Onjoinedlobby or Onconnected to master.
pls help :smile:

Comments