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 m3m3x · Jul 01, 2012 at 02:32 AM · guiinputtextkeyboarduser

Text Prompt Problem

I'm having a problem trying to get this object to be interactive in this environment I am building. When you approach a sign with this "wanderer_figure" I want a prompt to pop up within the GUI layer asking the player to press space to activate further text to be shown. Right now I have it coded as such:

 var showGUI : boolean = false; 
 var customGUI : GUISkin;
 
 function OnTriggerEnter (myTrigger : Collider) {
      if (myTrigger.gameObject.name == "Wanderer_Figure"){
         showGUI = true;
         }   
 }
 
 function OnTriggerExit (myTrigger : Collider) {
     if (myTrigger.gameObject.name == "Wanderer_Figure"){
         showGUI = false;
         } 
 }
 
 function OnGUI() {
 //activate custom skin settings/textures
     GUI.skin = customGUI;
     if(showGUI){
         GUI.Box (Rect (Screen.width/2-100, Screen.height/2+200,200,100), "Press SPACE to Interact");
     }
 
     if (Input.GetKeyDown ("space")){
         showGUI = false;
         GUI.TextField (Rect (Screen.width/2-100, Screen.height/2+200, 400,200), "TEST");
     }
 }

However, when I try and test this code, the second half of the GetKeyDown call doesn't work, even if I hold down the space key. I'm trying to see what the problem, and also am wondering how I might make this second set of text disappear after a certain period of time (or else disappear based on more user input).

I'm kind of a n00b at this, so any help would be greatly appreciated, and thorough explanation of any tips would would equally be extremely helpful!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Eric5h5 · Jul 01, 2012 at 02:34 AM

GetKeyDown only returns true for one frame, so the textfield will only appear for one frame. Although GetKey shouldn't be used in OnGUI, use Event.current.type == EventType.KeyDown instead. You can use that to toggle a boolean which would dictate whether the textfield is used or not.

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 m3m3x · Jul 01, 2012 at 05:07 PM 0
Share

Actually this advice is not good, and when I tried to implement this in the OnGui is gives me an error. I'm not sure what you are suggesting me to do, but how would you fix the above code using Event.current.type?

avatar image m3m3x · Jul 03, 2012 at 09:58 PM 0
Share

Also I'm having trouble trying to get this code to work only when you are within the collision limits. As it stands right now, regardless of where I stand, if I press the space bar the prompt will become activated, but I want to only allow for this to be the case when you are within the boundaries of this empty game object.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How do you get Unity to return a user input? 1 Answer

setting iPhoneKeyboard.text (or any workaround about resetting user input) in Android. 0 Answers

Android Keyboard .text String returning empty? 1 Answer

guiText.HitTest(Input.mousePosition) is not triggering 0 Answers

GUI Text Area that Reads / Writes / Saves 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