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 sooonism · Apr 20, 2014 at 05:11 PM · keyboardtouchscreen3d textgui.textfield

3d text to trigger mobile keyboard

I want to use 3d text as the button to trigger open mobile keyboard. Currently what I do is having a box as the collider as the child to the 3d text and change size accordingly to the length of the 3d text. Whenever you touch the box collider, it will trigger a GUI.Textfield and when you tap on the GUI.Textfield, the mobile keyboard will be launch for you to input. here's my code:

 void OnGUI () {
         if(inEditMode) {
             GUI.SetNextControlName ("hiddenTextField"); //Prepare a Control Name so we can focus the TextField
             GUI.FocusControl ("hiddenTextField");     //Focus the TextField
             guiString = GUI.TextField (new Rect (90, 100, 200, 25), guiString, 25);  //Display a TextField
             textComponent.text = guiString;
         }
 
                 if (Input.GetMouseButtonDown(0)) { 
             ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             if(Physics.Raycast(ray,out hit))
             {
                     if(hit.transform== boxcollider.transform) {
                     print("touched!!");
                         inEditMode = true;
                     }  else {
                         inEditMode = false;
                     }
             }
         }
 }

But I want to make do without tapping on the GUI.Textfield. Is it possible?

I tried an alternative method:

 if (Input.GetMouseButtonDown(0)) { 
             ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             if(Physics.Raycast(ray,out hit))
             {
                     if(hit.transform== boxcollider.transform) {
                     TouchScreenKeyboard.Open("", TouchScreenKeyboardType.Default, false, false, true, true);///<-- Added this line!!!
                         inEditMode = true;
                     }  else {
                         inEditMode = false;
                     }
             }
         }

That TouchScreenKeyboard.Open did trigger a keyboard but do not sync with GUI.Textfield. but if you tap on GUI.Textfield at this moment, another keyboard will open and that will sync. At this point, you have 2 layers of keyboard.

Any suggestions will be good.

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 KRanges · Apr 20, 2014 at 05:27 PM 0
Share

Have you tried passing focus to the field before opening the keyboard

avatar image sooonism · Apr 20, 2014 at 10:32 PM 0
Share

Tried. Still not working.

avatar image KRanges · Apr 21, 2014 at 12:59 AM 0
Share

re-read this. See the example, you need to retrieve the text from the keyboard and set your guiString to it. Be sure to check to make sure the keyboard is open like the example does.

2 Replies

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

Answer by KRanges · Apr 21, 2014 at 01:15 AM

You need to re-read this, after one pass i can see your error. Read the example they give. And see what the keyboard function is actually doing. It returns a type touchscreenkeyboard, which has variables you can access such as text(being the text typed into the keyboard) as you can see in the unity example you need to update you textfields text to relect that of the keyboards text.

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 sooonism · Apr 21, 2014 at 05:43 AM

Thanks to KRanges' advise, Now I figure out:

         ///define keyboard and important variables
 
         private TouchScreenKeyboard keyboard;//<--- add this line
     private bool inEditMode  = false;
     private string guiString;
 
       /// more codes here...
 
 void OnGUI () {
        if(inEditMode) {
          GUI.SetNextControlName ("hiddenTextField"); //Prepare a Control Name so we can focus the TextField
          GUI.FocusControl ("hiddenTextField");     //Focus the TextField
          guiString = GUI.TextField (new Rect (90, 100, 200, 25), guiString, 25);  //Display a TextField
          guiString = keyboard.text; //<-- add this line
          textComponent.text = guiString;
        }
  
                 if (Input.GetMouseButtonDown(0)) { 
          ray = Camera.main.ScreenPointToRay(Input.mousePosition);
          if(Physics.Raycast(ray,out hit))
          {
               if(hit.transform== boxcollider.transform) {
               print("touched!!");
               keyboard = TouchScreenKeyboard.Open(guiString, TouchScreenKeyboardType.URL);//<--- add this line
                  inEditMode = true;
               }  else {
                  inEditMode = false;
               }
          }
        }
 }

One thing though, if you do this, the normal keyboard is not working anymore.

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 KRanges · Apr 22, 2014 at 02:54 AM 0
Share

What do you mean normal keyboard? Ill try running your script in the morning and see what happens, never launched the keyboard manually myself.

avatar image sooonism · Apr 22, 2014 at 03:59 AM 0
Share

By normal $$anonymous$$eyboard I mean keyboard on your computer. $$anonymous$$y script only works with iPad at the moment. If you test it inside Unity nothing will happen. This as far as I know.

avatar image sooonism · Apr 22, 2014 at 04:03 AM 0
Share

There are a lot more things than just the script. If you are interested, P$$anonymous$$ me your email and I will send you the scenes and the scripts.

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

21 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

Related Questions

How to save text and display using Touch Screen Keyboard 1 Answer

how to hide ios keyboard but keep input field in focus for Voice Control 0 Answers

Touch interface with alternative keyboard in Unity3D? 1 Answer

How Can I Switch Focus Between 3D Text Buttons By Using The Keyboard? 0 Answers

How to call windows native keyboard and have it ontop of a fullscreen build 0 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