[UNET] send a string for other clients from server problem in UNET
hi
 i have a UI text in my scene and i want to change it, when clients type a word in their input text and send the word as a simple string between other clients.
 but when i testing it... it only send the world to the server and other clients text ui is not change !
 what i have to do ?
 here is my code :
 [Client]
         void ChatWriting ()
         {
             
             if (Input.GetKeyDown(KeyCode.Return))
             {
                 CmdChat(ChatFieldText.GetComponent<Text>().text);  
             }
         }
         [Command]
         public void CmdChat(string Cht)
         {
             ChatText.GetComponent<Text>().text = Cht;
         }
               Comment
              
 
               
              Answer by molx88 · Mar 09, 2016 at 08:40 PM
The [Command] attribute makes the method only run on the server. You need to send a [ClientRPC] command to update the ChatText.GetComponent().text field on the clients as well.
Answer by IMAN_SH · Mar 17, 2016 at 10:11 AM
i do this :
 [Command]
     void CmdChat(string cht)
     {
 
         GameObject[] Go = GameObject.FindGameObjectsWithTag("Player");
 
         for (int i = 0; i < Go.Length; i++)
         {
 
             Go[i].GetComponent<Chat_System>().Chatt = "Player" + transform.name + " : " + cht;
 
 
             Go[i].GetComponent<Chat_System>().ChatCounter++;
 
             if (Go[i].GetComponent<Chat_System>().ChatCounter >= 6 )
             {
                 Go[i].GetComponent<Chat_System>().ChatCounter = 1;
             }
 
         }
 
     }
and its working. when somebody enter text in textfield, the command find all players and change chat variable for all the players. is this wrong way ?
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                