Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
4
Question by CyberChroma · May 23, 2016 at 08:13 PM · inputfieldconversion

How to get a number from a UI input field

Long story short, I have a UI input field that I have set to only accept decimal inputs. When I go to access this input through code its type is string. How can I make this input a float or int so I can use math functions with it (add, subtract, multiply, divide, ect.)

Ps. I use C# for programming.

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

3 Replies

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

Answer by SirPaul · Dec 14, 2016 at 01:43 PM

@Superspeedy Here's an example for you of how to retrieve data from UI inputfield;

 InputField input;
 int integer_Value_we_Want;
 
  integer_Value_we_Want = int.Parse(input.text); //for integer 
  integer_Value_we_Want = float.Parse(input.text); //for float
  integer_Value_we_Want = double.Parse(input.text); //for double

and so on..

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 AswinBhaskaran · Jan 05, 2018 at 06:15 AM 0
Share

@SirPaul, Thanks a lot! I was having the same problem and this really helped me out!

avatar image DavidSJones · Mar 28, 2018 at 06:31 AM 0
Share

Thank you for a clear and simple answer. I helped a lot.

avatar image dustinRodda · Sep 24, 2019 at 04:01 PM 0
Share

Something to note here. If you parse a float or a double and try store it in an int then you will get an error. You cannot implicitly convert floats and doubles into ints.

avatar image
1

Answer by Ravenaige · Feb 28, 2020 at 12:12 PM

not working

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
1

Answer by YEX_ · Jun 01, 2021 at 04:39 PM

int.Parse() Does'nt work any more, you have to use TryParse()

InputField input; int number; int.TryParse(input.text, out int result); number = result;

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

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

11 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

Related Questions

Can someone please help me with implementing virtual joystick controls so that I can port my PC game to android? 0 Answers

iOS TouchScreenKeyboard closes and open when tapping on another InputField 4 Answers

Disable inputField navigation(Navigation between text or caret navigation) 1 Answer

Keyboard not opening when I am trying to shift to next input field through script 0 Answers

Cannot clear text from inputfield 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