Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Question Sending a message about connecting to the master client room

Discussion in 'Multiplayer' started by Hatemsla, Sep 7, 2022.

  1. Hatemsla

    Hatemsla

    Joined:
    Oct 17, 2021
    Posts:
    62
    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, the next two previous ones and his, etc. What can be done?
    Code (CSharp):
    1. public override void OnJoinedRoom()
    2.     {
    3.         _roomNameText.text = "Комната: " + PhotonNetwork.CurrentRoom.Name;
    4.         MenuManager.instance.OpenMenu("Room");
    5.  
    6.         Player[] players = PhotonNetwork.PlayerList;
    7.  
    8.         for (int i = 0; i < _playerList.childCount; i++)
    9.         {
    10.             Destroy(_playerList.GetChild(i).gameObject);
    11.         }
    12.  
    13.         for (int i = 0; i < players.Length; i++)
    14.         {
    15.             Instantiate(_playerNamePrefab, _playerList).GetComponent<PlayerListItem>().SetUp(players[i]);
    16.             Debug.Log($"{players[i].NickName} connected");
    17.         }
    18.  
    19.         _startGameButton.SetActive(PhotonNetwork.IsMasterClient);
    20.     }
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066