0

I'm trying to make a multiplayer game now, I'm trying to create a function to invite players if they have entered a name, but when the host has created a room, the list of players who are in the lobby does not appear. Even though other players have entered names. How do I make it? or there's an error in my code.

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

public class PlayerListPopUp : MonoBehaviour
{
    public Transform playerListContent;
    public GameObject playerPrefab;
    public GameObject playerListPanel;
    public Button openButton;
    // public Button inviteButton;


    // Start is called before the first frame update
    private void Start()
    {
        // Set up button listeners
        openButton.onClick.AddListener(ShowPlayerList);
        // closeButton.onClick.AddListener(HidePlayerList);
        
        // Hide the player list panel at start
        playerListPanel.SetActive(false);
    }

  private void ShowPlayerList()
{   
    playerListPanel.SetActive(true);
    // Clear the player list content
    foreach (Transform child in playerListContent)
    {
        Destroy(child.gameObject);
    }
        if(!PhotonNetwork.IsConnected) return;

    // Add player list items for each player who is not in a room
    foreach (Photon.Realtime.Player player in PhotonNetwork.PlayerList)
    {
        if (player.Room != null) continue; // skip players who are already in a room

        // Add player list items only for players who are in the lobby
    if (player.CustomProperties["status"] != null && player.CustomProperties["status"].ToString() == "lobby")
        {
            Debug.Log("Player NickName: " + player.NickName);
            GameObject item = Instantiate(playerPrefab, playerListContent);
            item.GetComponent<PlayerNameInvite>().SetUp(player);

            // // Add Invite button
            // Button inviteButton = item.transform.Find("InviteButton")?.GetComponent<Button>();
            // if (inviteButton != null)
            // {
            //     inviteButton.onClick.AddListener(() => { OnInviteButtonClick(player); });
            // }
        }
    }
}


     private void OnInviteButtonClick(Player player)
    {
        // Implement your invite functionality here
        Debug.Log("Inviting player: " + player.NickName);
    }
    private void HidePlayerList()
    {
        playerListPanel.SetActive(false);
    }
}


i hope someone help me

1 Answers1

0

Photon does not provide messages between arbitrary players outside of rooms. You can only send Events and RPCs within a room. There is Photon Chat to provide communication outside of rooms and you could also use some external matchmaking / messaging to send the actual invites.

Tobias
  • 164
  • 2