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 Steven Church · Oct 10, 2011 at 09:25 AM · javascriptguiongui

GUI Not updating

Hey all, I have had a look around and can not find a perfewct answer to my question. I am playing around with Unity again and think it is an amazing Game Engine. I am having a go at it with Javascript, I know C# but want to test my Javascript which is a little shoddy compared to other languages.

Anyhow, I want to use this script which I found when trying to find out an answer to my problem. However it is not updating the GUI at all! It just does nothing. I am using the standard controller which is included in the 2D tutorial.

 var stringToEdit = "Player1"; 
 var userHasHitOk : boolean = false;
 
 function Update() { 
         if(Input.GetKeyDown("enter")) { userHasHitOk = true; }
     }
     
     function OnGUI () {
     
         if (userHasHitOk)
         {
         
             GUI.Label (Rect (10, 10, 100, 30), "Hello " + stringToEdit);
         }
         else
         {
         GUI.Label (Rect (10, 10, 100, 30), "Enter Name:");
         
         stringToEdit = GUI.TextField (Rect (90, 10, 200, 25), stringToEdit, 40);
         }
     }

This code is in the CameraFocus.js file but it just does not update at all. It displays the GUI but no update.

Hope someone can help,

Thank you

Comment
Add comment · Show 3
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 syclamoth · Oct 10, 2011 at 09:40 AM 0
Share

Well, if it displays at all that means it's updating! In what way isn't it working?

EDIT: Oh I see. Just a sec...

avatar image Steven Church · Oct 10, 2011 at 09:45 AM 0
Share

Sorry, when the user presses enter it does not update correctly with the username they have entered into the box.

avatar image syclamoth · Oct 10, 2011 at 09:48 AM 0
Share

Yeah I worked that out. Answer up now!

1 Reply

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

Answer by syclamoth · Oct 10, 2011 at 09:44 AM

The problem here is that you are waiting for the user to press 'Enter' after they type some text into a text field. Unfortunately, the default behaviour for such fields is that they prevent normal Input.keyPress-type functions from working, so that the text field can be entered without the player accidentally using their input keys!

Recently the boolean value 'Input.eatKeyPressOnTextFieldFocus' has been added, which lets you override that behaviour. Just set

 Input.eatKeyPressOnTextFieldFocus = false;

at the top of your script, and you'll be good to go!

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 Steven Church · Oct 10, 2011 at 09:59 AM 0
Share

Still nothing. Adding this to the top makes no difference.. Strange

avatar image syclamoth · Oct 10, 2011 at 10:10 AM 0
Share

That's odd. Does it work if you don't click the text field first?

avatar image Steven Church · Oct 10, 2011 at 10:12 AM 0
Share

No need to worry solved it. Enter seems to be looking for $$anonymous$$eypad Enter not Return.. Silly me. Changed this line to:

if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Return)) { userHasHitOk = true; }

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

turn off items from GUI 0 Answers

GUI.Window only shows for one frame under all circumstances 2 Answers

Weird GUI error (script included) 1 Answer

using GUI scrollView for multiple onGUI functions 0 Answers

GUI opacity. 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