Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    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:
    49
    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:
    2,972