I'm making a chat for my multiplayer game and I'm having problems adding text to a text ui component. When the text gets added for the first time everything is fine. However, if I try to add more text to the component it just doesn't work. Here's the text adding:
public GameObject chattext;
private void OnChatMessage(LobbyChatMsg_t result)
byte chatbytereceived = new byte;
SteamMatchmaking.GetLobbyChatEntry(vars.GetComponent<VarController>().currentlobby, Convert.ToInt32(result.m_iChatID), out lastchatsender, chatbytereceived, 201, out chattype);
if (chattext.GetComponent<Text>().text.Length != 0)
chattext.GetComponent<Text>().text += Environment.NewLine + Encoding.UTF8.GetString(chatbytereceived);
chattext.GetComponent<Text>().text += Encoding.UTF8.GetString(chatbytereceived);
Debug.Log("Received message:" + Encoding.UTF8.GetString(chatbytereceived));
Debug.Log("Current text is " + chattext.GetComponent<Text>().text);
Here's my entire project.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
144 People are following this question.
Change UI Text in script
How to render text on top of the objects that are generated on the map using a script?
In updating some score text, why should we use the Update function instead of separate functions?
Can't see Text UI in game view
Text in UI disappears when clicked on