Home > database >  Sending a message about connecting to the master client room on unity photon
Sending a message about connecting to the master client room on unity photon

Time:09-11

I need to send a message to the master that the player has connected to the room.
The problem is that in my case I cannot use RPC or RaiseEvent, because there is not a single PhotonView in the room.
I tried to do it without them, but when a new player enters, it seems to send information about all the players, that is, the master can only see his message, the next player has the master's message and his, and the next two previous ones and his, etc.

What can be done?

public override void OnJoinedRoom()
{
    _roomNameText.text = "Комната: "   PhotonNetwork.CurrentRoom.Name;
    MenuManager.instance.OpenMenu("Room");

    Player[] players = PhotonNetwork.PlayerList;

    for (int i = 0; i < _playerList.childCount; i  )
    {
        Destroy(_playerList.GetChild(i).gameObject);
    }

    for (int i = 0; i < players.Length; i  )
    {
        Instantiate(_playerNamePrefab, _playerList).GetComponent<PlayerListItem>().SetUp(players[i]);
        Debug.Log($"{players[i].NickName} connected");
    }

    _startGameButton.SetActive(PhotonNetwork.IsMasterClient);
}

CodePudding user response:

Solution

public override void OnPlayerEnteredRoom(Player newPlayer)
{
    Instantiate(_playerNamePrefab, _playerList).GetComponent<PlayerListItem>().SetUp(newPlayer);
    Debug.Log($"The {newPlayer.NickName} is connected");
}
  • Related