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 GameGuy · Feb 05, 2012 at 02:29 PM · standalonetextfieldosx

Closing Textfield via Input.GetKeyDown not working under MacOSX(No problem under Windows)

I use the attached code to load a level on Input.GetKeyDown, but it is not working under MacOSX, under Windows it is working just fine!

I guess it has to do with the Textfield, because closing a normal Gui.Button with Input.GetKeyDown is working fine, but I was not able to narrow it down.

 var Username = "";
 //
     function ShowCustomNameWindow (windowID : int)
     {
         //
         GUI.Label (Rect (100,100,300,45), "ENTER YOUR NAME:");
         //
         GUI.SetNextControlName ("Username");
         GUI.FocusControl ("Username");
         Debug.Log(GUI.GetNameOfFocusedControl);
         //
         Username = GUI.TextField (Rect (142,142,178,35), Username,11);
         //
         if(Input.GetKeyDown(KeyCode.Return) && Username.Length != 0 
            ||Input.GetKeyDown(KeyCode.KeypadEnter) && Username.Length != 0) 
         //
            {
             //
             Application.LoadLevel("xyz");
            }
     
     }
Comment
Add comment · Show 8
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 Eric5h5 · Feb 05, 2012 at 07:18 PM 0
Share

I don't know if it's related, but you should stay away from the Input classes in OnGUI code, and use Event.current ins$$anonymous$$d.

avatar image GameGuy · Feb 05, 2012 at 07:48 PM 0
Share

Uhhh!? ...good to know about that! I´ll try Event.current out now.

avatar image GameGuy · Feb 05, 2012 at 09:25 PM 0
Share

When I use a simple "Debug.Log("Current detected event: " + Event.current)" in this function, the returned keyCode output is None(But only for Return & Enter, normal keys are returning their valid keyCode output). Using this Debug.Log in normal OnGUI function the returned keyCode output for Enter & Retun is is correct. Any ideas?

avatar image Eric5h5 · Feb 05, 2012 at 09:35 PM 0
Share

Try checking the input before the textfield code, since it's probably eating the return key event.

avatar image GameGuy · Feb 05, 2012 at 11:34 PM 0
Share

Yes, that is true the textfield was eating the event! But when putting the Event code before the textfield, I was not longer able to control Username.Length correctly. So I came up with (Event.current.Equals(Event.$$anonymous$$eyboardEvent ("[enter]")) which works just fine also after the textfield.

Show more comments

2 Replies

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

Answer by GameGuy · Feb 06, 2012 at 09:04 PM

First of all Input.GetKeyDown should not be used in OnGui functions, for detecting any key use Event.current.

So I changed the function to :

 var Username = "";
 //
     function ShowCustomNameWindow (windowID : int)
     {
         //
         GUI.Label (Rect (100,100,300,45), "ENTER YOUR NAME:");
         //
         GUI.SetNextControlName ("Username");
         GUI.FocusControl ("Username");
         Debug.Log(GUI.GetNameOfFocusedControl);
         //
         Username = GUI.TextField (Rect (142,142,178,35), Username,11);
         //
         if((Event.current.Equals(Event.KeyboardEvent ("[enter]"))&& Username.Length != 0) 
         //
            {
            //
            Application.LoadLevel("xyz");
            }
 
     }

Basically Input.GetKeyDown(KeyCode.KeypadEnter) turned into (Event.current.Equals(Event.KeyboardEvent ("[enter]"))

Thanks to Eric5h5, who helped me to find this solution!

Comment
Add comment · 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
0

Answer by unimechanic · Jul 03, 2013 at 04:14 PM

This example might help too:

http://forum.unity3d.com/threads/188202-Simple-dynamic-list-editor

Comment
Add comment · 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

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

6 People are following this question.

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

Related Questions

Multi-monitor spanning on OSX 1 Answer

Using Image Component in OSX standalone app crashes build 0 Answers

Can't find OSX Standalone log file 2 Answers

Crash reports in OSX/Linux no longer working in 5.2? 0 Answers

Capture Single Screen Mac alternative ? 1 Answer


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