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 Yanka200 · Jan 01, 2013 at 12:12 AM · inputstringconvert

Redirecting input with event.current.character?

Soo I searched around on the forum, like a beginner should, and I found what I was looking for [here][1], but it was in C#, and I am working in JavaScript. So I tried to understand how the code worked, and rewore as much as possible. I changed it into this, onGui:

 var InputKey = Event.current.character;
 if (InputKey == 'a')
 {
  //Remove the inputtet character
 }

Now, this was just an example to get an idea of how it worked, for a single letter, but couldn't get that to work either. Anyone mind retouching the code so it works as intented, eg. restricts any non character a-z or number 0-9 from being entered (without using RegEx, due to Webplayer target)

Thank you in advance, and may the new year return less compile error than the previous! [1]: http://answers.unity3d.com/questions/18736/restrict-characters-in-guitextfield.html

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
1

Answer by Eric5h5 · Jan 01, 2013 at 12:29 AM

Unityscript doesn't use the single-quote method for indicating chars (both single and double quotes are used for strings). Instead refer to the index of the string. If you're using a single character in a string, naturally the only index possible is 0.

 if (Event.current.character == "a"[0]) {
     Event.current.character = "\0"[0];
 }

Note that \\0 is an escaped sequence meaning "null char", so it's actually one character even though it looks like two.

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 Yanka200 · Jan 01, 2013 at 10:13 AM 0
Share

This doesn't work. I appreciate your correction of the syntax, but it doesn't solve my problem, of restricting user input in text field, to only letters and numbers.

avatar image Eric5h5 · Jan 01, 2013 at 05:30 PM 0
Share

It does work. Look at my answer in the question you linked to, then substitute the syntax I showed above in order to use it in Unityscript.

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Download a WWW int? Or convert? 1 Answer

Is there a way to convert microphone input to a string? 2 Answers

Pulling the first two characters from a string. Code not working. 1 Answer

how to convert a float to string[] 1 Answer

iOS keyboard - limit number of keyboard characters 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