Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Borzi · Mar 05, 2014 at 04:28 PM · inputrpcgetkeydownenter

Enter not being called

Hello! I am trying to get my chat message to be sent when the player has entered something into the textbox and presses enter, but for some odd reason Unity does not recognise when I press Enter/Return (I have done a debug on the if(Message != null) to make sure that it should run). It would be much appreciated if someone could help me on this matter!

 void OnGUI()
     {
     if(GUIManager.Instance.Chatting == true)
         {
         GUIManager.Instance.isBusy = true;
         GUI.SetNextControlName("MessageControl");
         Message = GUI.TextArea(new Rect(Screen.width * (0.1f/10f), Screen.height * (0.112f/0.129f), Screen.width * (0.5f/2.3f), Screen.height * (0.3f/6.3f)), Message, 25);
         GUI.FocusControl("MessageControl");
         if(Message != null)
         {
         if(Input.GetKeyDown("enter") || Input.GetKeyDown("return"))
             {
             Debug.Log("Clicked Enter");
             if(Message != null || Message != "")
                 {
                 GUIManager.Instance.Send_Public_AddChatMessage(NetworkManager.Instance.PlayerName + ": " + Message);
                 Message = "";
                 GUIManager.Instance.Chatting = false;
                 GUIManager.Instance.isBusy = false;
                 }
             else
                 {
                 GUIManager.Instance.Chatting = false;
                 GUIManager.Instance.isBusy = false;
                 }
             }
         }
         }
     }
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dblfstr · Mar 05, 2014 at 04:46 PM 0
Share

You should do your Input and $$anonymous$$ey presses in Update. Leave OnGUI() for showing the GUI and interacting with GUI elements (buttons, labels, etc).

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by fifthknotch · Mar 05, 2014 at 04:44 PM

Right now your GUI TextArea views "enter" as just another character. You need to specify a keyboard event to check if a specific key was pressed.

More info found here: http://docs.unity3d.com/Documentation/ScriptReference/Event.KeyboardEvent.html

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fifthknotch · Mar 05, 2014 at 04:52 PM 1
Share

They are not. GUI text area overrides Get$$anonymous$$ey. Check out this unity forum. they have the same issue: http://forum.unity3d.com/threads/69361-GUI-TextField-submission-via-quot-return-quot-key

avatar image Borzi · Mar 05, 2014 at 04:59 PM 0
Share
 if(e.keyCode == $$anonymous$$eyCode.Return || e.keyCode == $$anonymous$$eyCode.$$anonymous$$eypadEnter)
             {
             Debug.Log("Clicked Enter");
             if($$anonymous$$essage != null || $$anonymous$$essage != "")
                 {
                 GUI$$anonymous$$anager.Instance.Send_Public_AddChat$$anonymous$$essage(Network$$anonymous$$anager.Instance.PlayerName + ": " + $$anonymous$$essage);
                 $$anonymous$$essage = "";
                 GUI$$anonymous$$anager.Instance.Chatting = false;
                 GUI$$anonymous$$anager.Instance.isBusy = false;
                 }
             else
                 {
                 GUI$$anonymous$$anager.Instance.Chatting = false;
                 GUI$$anonymous$$anager.Instance.isBusy = false;
                 }
             }

Works perfectly thank you guys!

avatar image
1

Answer by perchik · Mar 05, 2014 at 04:34 PM

Try

 Input.GetKeyDown(KeyCode.Return)
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image perchik · Mar 05, 2014 at 04:35 PM 0
Share

Perhaps also try Get$$anonymous$$eyUp

avatar image Borzi · Mar 05, 2014 at 04:45 PM 1
Share

Nope! I think the real problem is that Unity thinks I am chatting and therefore not recognising the button press as a command. When I press enter, it merely goes a line down.

avatar image perchik · Mar 05, 2014 at 04:48 PM 0
Share

Ah! Then, @Fifth$$anonymous$$notch's solution below is what you want.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Enter/Exit Vehicle with the same key? 2 Answers

GetKeyDown code turned into a int issue [SOLVED] 1 Answer

How to play animation after pressing return 3 times ? 1 Answer

Having GetButton act like GetKeyDown 1 Answer

Trying to see how long the player holds down a key. GetKeyDown & GetKeyUp behaving oddly. (C#) 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges