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 Omer.Hussain · Apr 15, 2014 at 01:46 PM · inputkeyboardtextboxwriting to text

how to get Inputs from touch keyboard...

Hi...can anyone tell my how do we get input from the touch keyboard.. like enter your name in a box .. when we touch the box keyboard appear and write your name and that name show on the other scene.. like it say on ther other scene" welcome XYZ"

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by salvador007 · Apr 17, 2014 at 09:49 AM

Yes, u can use GUI.TextField for solution to this problem.

Using this you can even restrict maximum string length.

alt text

:)


screen shot 2014-04-17 at 2.32.52 pm.png (49.5 kB)
Comment
Add comment · Show 1 · 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 Omer.Hussain · Apr 18, 2014 at 07:05 AM 0
Share

@salvador007 your suggestion is good but i have impleted that in anotherway only thing left is when keyboard is done writing... see my above comment

avatar image
0

Answer by OSG · Apr 15, 2014 at 01:51 PM

GUI.TextField will do all work for you. Just save string from it in some global variable and get it when you need

edit: in Update() use TouchScreenKeyboard.done to catch the moment when user entered his name. More info about TouchScreenKeyboard here.

Comment
Add comment · Show 6 · 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 Omer.Hussain · Apr 17, 2014 at 08:14 AM 0
Share

yahhh ... can you explain me how actually we can restrict the user to write name up to 15 characters ...if they write above the limit of 15 character show notification to write in between 0-15 character ? is it possible in unity ? and i am showing the text through the GUIText...
#pragma strict

 public var enterName:GUIText;
 var inputText : String = "Enter name";
     private var keyboard : TouchScreen$$anonymous$$eyboard;
     // Updates button's text while user is typing
     function OnGUI() {
         if (GUI.Button(Rect(0, 10, 200, 32), inputText))
 
             keyboard = TouchScreen$$anonymous$$eyboard.Open(inputText);
 
         if (keyboard)
             inputText = keyboard.text;
             enterName.text=inputText;
     }
avatar image OSG · Apr 17, 2014 at 09:16 AM 0
Share

Try this

 public var enterName:GUIText;
     var inputText : String = "Enter name";
         private var keyboard : TouchScreen$$anonymous$$eyboard;
         // Updates button's text while user is typing
         function OnGUI() {
            if (GUI.Button(Rect(0, 10, 200, 32), inputText))
              keyboard = TouchScreen$$anonymous$$eyboard.Open(inputText);
      
            if (keyboard) {
              inputText = keyboard.text;
              if(inputText.length < 15)
                enterName.text = inputText;
              else 
                GUI.Label(Rect(0, 50, 200, 32), "Name is too long. Use less than 15 chars");
            }
         }
avatar image Omer.Hussain · Apr 18, 2014 at 06:59 AM 0
Share

@OSG now i have implemented it like this way.. with button as it was before and i give the GUIStyle to button so it doesn't show the black background and i adjusted the button position and it show on the exact writing box so when i touch the writing box it show keyboard and in the inspector,i set the GUISTyle text cliping enable so the text doesn't go out of the box and through lenght method i can measure the lenght ....now only thing left is when i press the done button it should play an iTween animation or load new level ...i tried to make it happen like below code but it showing me error on keyboad.done (NullReferenceException: Object reference not set to an instance of an object touchinput.OnGUI () (at Assets/Scripts/touchinput.js:18) )

 var inputText : String = "Enter name";
     var guiStyle:GUIStyle;
     var timer:float;
     var done: boolean; 
     private var keyboard : TouchScreen$$anonymous$$eyboard;
     // Updates button's text while user is typing
     function OnGUI() 
         {
         timer+=Time.deltaTime;
         if(timer>7)
         if (GUI.Button(Rect(Screen.width/2-200,Screen.height/2-220,Screen.width/2,Screen.height/18), inputText,guiStyle))
 //            print("IN");
     {
             keyboard = TouchScreen$$anonymous$$eyboard.Open(inputText, TouchScreen$$anonymous$$eyboardType.Default);
     }
         if (keyboard.done)
             
             inputText = keyboard.text;
             var lenght= inputText.length;
             print(lenght);
             
     }
 
avatar image Omer.Hussain · Apr 18, 2014 at 07:01 AM 0
Share

from Here i had that done method

avatar image Omer.Hussain · Apr 18, 2014 at 07:54 AM 0
Share

Funny thing .... i don't know its a bug or what... in unity console it show the error (NullReferenceException: Object reference not set to an instance of an object touchinput.OnGUI () (at Assets/Scripts/touchinput.js:18) ) .....but when i build and run on my android device it works fine lolx :D... ... now whats this ? .. :D #pragma strict

     var inputText : String = "Enter name";
     var guiStyle:GUIStyle;
     var timer:float;
 //    var done: boolean; 
     private var keyboard : TouchScreen$$anonymous$$eyboard;
     // Updates button's text while user is typing
     function OnGUI() 
         {
 
         if (GUI.Button(Rect(Screen.width/2-200,Screen.height/2-220,Screen.width/2,Screen.height/18), inputText,guiStyle))
 //            print("IN");
     {
             keyboard = TouchScreen$$anonymous$$eyboard.Open(inputText, TouchScreen$$anonymous$$eyboardType.Default);
     }
         if (keyboard)
         {    
             inputText = keyboard.text;
             var lenght= inputText.length;
         }
 //            Application.LoadLevel(0);
     if(keyboard.done)
     {
         Application.LoadLevel(0);    
     }
             
     }
 
Show more comments

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

22 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

Related Questions

Checking whether string is a valid Input.Key 1 Answer

A node in a childnode? 1 Answer

How to distinguish between multiple keyboards? 1 Answer

How can i make button on iOS instead key 0 Answers

What just happened to my Unity!? 3 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