- Home /
Question by
ImPhilip · Jul 30, 2014 at 04:08 PM ·
focuschatmessagegui.textfield
Press enter to start typing and send message
Right now I have it so you have to click in textbox then type your message and click send button to send the message.
I want it so I can press the enter key then start typing and then press enter to send the messege. How could I achieve it?
if(menuSrc.viewChat){
GUI.BeginGroup(chatRect, "");
GUI.Box(new Rect(0,0,chatPanelSizeX, chatPanelSizeY), "");
sizeY=margin;
GUI.Box(new Rect(margin,sizeY,chatBoxSizeX, chatBoxSizeY), "");
chatScroll = GUI.BeginScrollView (new Rect (margin,sizeY,chatBoxSizeX,chatBoxSizeY), chatScroll, new Rect(0,0, chatBoxSizeX-margin*4, 20*menuSrc.networkSrc.chatContent.Count+margin*2));
for(int i = 0; i < menuSrc.networkSrc.chatContent.Count; i++){
GUI.Label(new Rect(margin*2,sizeY,chatBoxSizeX-margin*2, 30), menuSrc.networkSrc.chatContent[i]);
sizeY+=20;
}
GUI.EndScrollView();
textChat=GUI.TextField(new Rect(margin, chatPanelSizeY-margin-chatFieldSieY, chatFieldSizeX, chatFieldSieY), textChat); // messege bar
if(GUI.Button(new Rect(chatFieldSizeX+margin*2, chatPanelSizeY-margin-chatFieldSieY, chatButtonSizeX, chatButtonsSizeY), menuSrc.text.gmChatButtonTxt) || Input.GetKeyUp(KeyCode.Return)){
if(textChat != "") {
string message = menuSrc.networkSrc.playerDataSrc.nameInGame+" : "+textChat; // name : messege
int maxChar = (int)Math.Round((chatBoxSizeX-20) / 6.8f);
if(message.Length > maxChar){
message = message.Substring(0, maxChar);
}
ChatMessage(message);
textChat = "";
}
}
GUI.EndGroup();
}
}
}
private void ChatMessage(string message){
menuSrc.networkSrc.SendChatMessage(message);
}
}
Comment
Your answer
Follow this Question
Related Questions
Not loosing focus 0 Answers
Defocus input line? 0 Answers
Multiplayer "
How to adjust sending SMS with the help a chat bot? 0 Answers
Building a Message Board 0 Answers