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 stingman · Feb 25, 2013 at 01:09 AM · androidiphoneplayerprefskeyboardtouchscreen

How to save text and display using Touch Screen Keyboard

Hey guys,

A user clicks a button and the iphone keyboard pops up. They are prompted to enter their player's name. I want to be able to save the text they enter in Player Prefs so I can grab their name throughout the game. Seemingly simple but nothing is being saved. After the user taps "return" or "done" on the keyboard there is nothing saved but an empty string in the PlayerPrefs. Here's the code:

 private string playerName;
 
 void NamePlayer() {
 
         TouchScreenKeyboard keyboard;
         keyboard = TouchScreenKeyboard.Open(playerName, TouchScreenKeyboardType.Default, false, false, false, false, "Enter Name");
         if (keyboard.active) 
         playerName = keyboard.text;
         PlayerPrefs.SetString("PlayerName",playerName);
 }
Comment
Add comment · Show 6
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 hoy_smallfry · Feb 25, 2013 at 01:15 AM 0
Share

Have you tried using 'keyboard.done' ins$$anonymous$$d of 'keyboard.active'? 'active' is for when the keyboard is still visible, 'done' is for when its gone away.

avatar image stingman · Feb 25, 2013 at 01:38 AM 0
Share

Hey ya I've tried using keyboard.done. That doesn't do anything for me. originally I had it set up like so:

 if (keyboard.active)
 playerName = keyboard.text;
 if (keyboard.done)
 PlayerPrefs.SetString("PlayerName", playerName);
avatar image girishgowdayt · Jun 12, 2013 at 06:36 AM 0
Share

is there any ways to implement Touch Screen $$anonymous$$eyboard for Windows PC Platform???

avatar image AlucardJay · Jun 12, 2013 at 06:52 AM 0
Share

@girishgowdayt : Please don't post comments as answers. Post comments by clicking the [add new comment] button, a window then open for you to type in. Answer fields are for answers only, as this is a knowledge base.

  • Read this page : http://answers.unity3d.com/page/newuser.html

  • Please watch : http://video.unity3d.com/video/7720450/tutorials-using-unity-answers

avatar image AlucardJay · Jun 12, 2013 at 06:54 AM 0
Share

I have never done anything for windows touch. I did a quick search, perhaps something here or one of the links mentioned might help :

  • http://answers.unity3d.com/questions/363422/windows-8-touch-support.html

  • http://www.google.com/search?btnG=1&pws=0&q=unity+windows+8+touch

Show more comments

1 Reply

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

Answer by AlucardJay · Feb 25, 2013 at 02:48 AM

This is what I wrote to use the iPhone keyboard :

 #pragma strict
 
 public var kBoardString : String = "";
 
 private var tempString : String = "";
 private var keyboard : iPhoneKeyboard;
 private var iskBoardOpen : boolean = false;
 
 function Update() 
 {
     kBoard0();
 }
 
 function kBoard0()
 {
     // keyboard = iPhoneKeyboard.Open( tempName : String, iPhoneKeyboardType.Default, Auto-Correct, Multi-Line, Secure, Alert, "Text Placeholder" );
     
     if ( !iskBoardOpen ) 
     {
         keyboard = iPhoneKeyboard.Open( tempString, iPhoneKeyboardType.Default, false, false, false, false, "Default Keyboard" );
         iskBoardOpen = true;
     }
     
     if ( keyboard.done ) 
     {
         kBoardString = keyboard.text;
         tempString = "";
         iskBoardOpen = false;
     }
     else
     {
         kBoardString = keyboard.text;
     }
 }
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 stingman · Feb 25, 2013 at 03:01 AM 0
Share

Alucardj, Thank you for the response. I realized what the issue was with my script. I was trying to set a Player Pref during the same frame as when the keyboard was opened. So obviously it wasn't working. I noticed you placed your code to run in the Update function and that's why yours works and $$anonymous$$e doesn't. I either need to do something similar or initate a coroutine and yield while the keyboard is active. Thanks for the tip.

avatar image AlucardJay · Feb 25, 2013 at 03:04 AM 0
Share

Yes, it was some experimenting to get this right. The kBoard function call was actually in a switch-case, but called every frame while waiting for input, hence the boolean. I was having trouble reading tempString, so it is just a null variable for the iPhone$$anonymous$$eyboard command to use. Glad this helped =]

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

12 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

Related Questions

iPhoneKeyboard.area works? 2 Answers

TouchScreenKeyboard not working with GUI.TextArea (tested with Android tablet) 0 Answers

How can I tell if the device I am on supports touch? 4 Answers

Remove "Preview text line" above keyboard input text on Android and iPhone 1 Answer

What is the command to check whether player is touching the screen or not?? 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