- Home /
Enter key no longer sends message when I change text styles
I am trying to style some input text so the user can change colors, font, etc. I have 'textStyle' set to the users current font settings, but I want the input to show these settings (ie. if they choose green text, show green text as they type in the input).
This works, when I don't set the style of the input
GUI.SetNextControlName ("MessageInput");
newMessage = GUI.TextField(new Rect(10, curHeight - sendHeight - 15, curWidth - sendWidth - 25, sendHeight), newMessage, 300);
GUI.skin = oldSkin;
if (GUI.Button(new Rect(curWidth - sendWidth - 10, curHeight - sendHeight - 15, sendWidth, sendHeight), "Send") || (Event.current.type == EventType.keyDown && Event.current.character == '\n'))
{
print(newMessage);
GetComponent<LobbyGUI>().sendChatMessage(newMessage);
newMessage = "";
}
But, when I set my Input to a style, the Enter key no longer works... can someone explain to me why this is?
Example :
newMessage = GUI.TextField(new Rect(10, curHeight - sendHeight - 15, curWidth - sendWidth - 25, sendHeight), newMessage, 300, textStyle);
That changes the color, but the enter key no longer works to send the message.
Answer by Neodim · Jun 04, 2012 at 03:44 PM
Try
Event.current.isKey && (Event.current.keyCode == KeyCode.KeypadEnter || Event.current.keyCode == KeyCode.Return)
instead of
Event.current.type == EventType.keyDown && Event.current.character == '\n'
Your answer
![](https://koobas.hobune.stream/wayback/20220613040905im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Enter not being called 2 Answers
Enter and Return in TextField in Mac Not Working 1 Answer
IPointerEnterHandler / IPointerExitHandler and touch 1 Answer
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers
gameObject A detecting keyboard inputs from gameObject B. 1 Answer