• 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 Abirami-Govindarajan · Jun 08, 2018 at 10:48 AM · uiinstantiateinputfieldadd

How to insantiate an Inputfield which is populated with numerical values and to add the values of the field to get an output values?

I have instantiated a prefab Input Field and each input field has some Integer values, i'm unable to add the values of the instantiated input field to get an output!!!!!!!!!

Comment
Add comment · Show 5
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 tormentoarmagedoom · Jun 08, 2018 at 11:06 AM 0
Share

Good day.

What you mean with "add values" ? add values where, inside the textbox? why you need to do this? an input is for players to type things..

And what you mean for get an output?

A textbox have the property text, which is a string variable, you can read it, acces and set it. I don't get what you mean by "output".

Please explain more..

Thanks! Bye!

avatar image Abirami-Govindarajan tormentoarmagedoom · Jun 08, 2018 at 11:30 AM 0
Share

Good day :D

i entered numerical values into the input fields and for adding used float.parse and then into string.

avatar image tormentoarmagedoom Abirami-Govindarajan · Jun 08, 2018 at 11:42 AM 0
Share

i understand even less than before.. are you sure you are using the correct names of the things?

"you" are entring numbers to an input textbox? ¿why? why dont just simple use a text? ¿during play? or the user will do it?

Show more comments
avatar image Harinezumi · Jun 08, 2018 at 12:12 PM 0
Share

If I understand it correctly, you instantiated a number of InputFields, then (in play mode) entered numerical values into them, and you want to turn get the values in them, add them up, and return an output (possibly in string).
For this, you need to get the content of each InputField from InputField.text, parse the value with float.Parse(), store the result in a float, add the values. floats usually automatically convert to string, but that doesn't happen, you can use ToString() for that.
I see that you already mentioned doing this, but didn't work. What is the problem?

Some code:

 List<InputField> inputFields; // I assume you have your InputFields in this list
 Text outputLabel; // I assume you want to output the sum onto a Text, but the code below would be the same for an InputField
 float sum = 0;
 for (int i = 0; i < inputFields.Count; ++i) {
     float value;
     if (float.TryParse(inputFields[i].text, out value)) { sum += value; }
     else { Debug.LogError("Content of InputField " + i + " is not a valid number!"); }
 }
 outputLabel.text = sum.ToString();

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

158 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image

Related Questions

Request feedback for C# script (instantiating UI elements depending on Player Input) 0 Answers

InputField instance isFocused always return false. 0 Answers

Instantiating into UI objects 1 Answer

How can I instantiate parented ui objects above previously instantiated children? 1 Answer

Instantiate prefab at specific path 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