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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

[Solved] Lobby Chat Not Working

Discussion in 'Multiplayer' started by IchBinJager, Mar 27, 2016.

  1. IchBinJager

    IchBinJager

    Joined:
    Dec 23, 2014
    Posts:
    127
    So I have it that when people join the lobby panel gets activated which is the same for everyone, and when someone starts hosting I have the lobby panel set active also. So I would think this would work for OnEditString() for the chat field

    Code (CSharp):
    1. public void Chat_Sent(string written_string)
    2.     {
    3.    
    4.         ALobbyPlayer this_player;
    5.        
    6.        
    7.        
    8.    
    9.         foreach ( GameObject LPlayer in GameObject.FindGameObjectsWithTag("Player") )
    10.         {
    11.            
    12.            
    13.            
    14.             if ( LPlayer.GetComponent<ALobbyPlayer>().isLocalPlayer )
    15.             {
    16.                 this_player = LPlayer.GetComponent<ALobbyPlayer>();
    17.                 this_player.CmdSend_Chat_Msg(LPlayer.gameObject.name + ": " + written_string);
    18.                
    19.                
    20.                 GameObject.Find("Chat Field").GetComponent<InputField>().text = "";
    21.                 return;
    22.                
    23.             }
    24.            
    25.            
    26.        
    27.         }
    28.        
    29.        
    30.        
    31.        
    32.        
    33.        
    34.     }
    Code (csharp):
    1.  
    2.  
    3. [ClientRpc]
    4.    
    5.    void RpcUpdate_Player_List()
    6.    {
    7.    
    8.    }
    9.    
    10.    void RpcRelay_Msg(string to_relay)
    11.    {
    12.      GameObject.Find("Lobby Chat").GetComponent<Text>().text += "\n" + to_relay;
    13.    }
    14.  
    15. public void CmdSend_Chat_Msg(string chat_msg)
    16.    {
    17.      if ( !isClient )
    18.      {
    19.        return;
    20.      }
    21.      
    22.      RpcRelay_Msg( gameObject.name + ": " + chat_msg);
    23.      
    24.    }
    25.  
    26.  
    Any idea what the issue is?
     
  2. IchBinJager

    IchBinJager

    Joined:
    Dec 23, 2014
    Posts:
    127
    I'm still not able to get it working.
     
  3. srylain

    srylain

    Joined:
    Sep 5, 2013
    Posts:
    159
    For one, you don't have the [Command] attribute above your CmdSend_Chat_Msg() function. You also don't have the [ClientRpc] attribute above RpcRelay_Msg().

    Not sure if there's any other problems, but you also need to be sure that your are sending the Command from an object that also has a NetworkIdentity and has the "Local Player Authority" checked.
     
  4. IchBinJager

    IchBinJager

    Joined:
    Dec 23, 2014
    Posts:
    127
    Local Player Authority was not checked on the prefab, I'm really sorry. Thanks so much for your help.
     
    Last edited: Mar 29, 2016