• 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
Question by jacobjones · Mar 19, 2015 at 11:47 AM · user interfacetext input

How to use inputfield with a button and text?

I want to get text from an InputField and when I press a button, display it in the UI Text box.

I have seen t$$anonymous$$s unanswered question so many places, and I finally have the answer. I made the question simpler than my original one to make it all clear.

Comment
KUFgoddess

People who like this

1 Show 2
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 jacobjones · Mar 19, 2015 at 07:50 AM 1
Share

I've gone through those. They give an overview of what the components are but don't talk at all about how to use them with each other. Do you know where I can find that kind of information?

avatar image jacobjones · Mar 19, 2015 at 07:57 AM 1
Share

There isn't even one on input field....

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by DiegoSLTS · Mar 20, 2015 at 01:30 PM

It's pretty easy, you need a script that has a reference to the InputField and the Text, and a function that takes the text from the input and set it as the text of the Text when called. Then, setup that function to be called when the button is pressed.

The script should look similar to t$$anonymous$$s: using UnityEngine; using UnityEngine.UI;

 public class InputFieldToText : MonoBehaviour {
     public InputField Field;
     public Text TextBox;
 
     public void CopyText() {
         TextBox.text = Field.text;
     }
 }

Now:

  1. Create a Button, an InputField and a Text

  2. Add that InputFieldToText script to any object, select that object and drag and drop the InputField and the Text in the proper slots for that script.

  3. Select the Button and look at the inspector, there's a Box at the bottom to add functions that should be called when the button is clicked.

  4. Press the "+" button at the bottom right of that box, it'll add a new line.

  5. Drag and drop the game object that has the InputFieldToText component into the box where it says "(None) Object", it will enable the drop down button next to it.

  6. Click in that dropdown, look for the InputFieldToText entry in that list and select it.

  7. It will display another menu with valid functions you can call from that script, select the CopyText function.

That's it, run the game, type some text in the input field and press the button.

Also, if you can't find tutorials explaining how to use somet$$anonymous$$ng there's always the API documentation. You can see there that the InputField and the Text classes both have a "text" property.

Comment
jacobjones
qanqa
KUFgoddess
LukiPupsiii

People who like this

4 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 jacobjones · Mar 21, 2015 at 04:18 PM 0
Share

It works. Thank you so much for taking the time to answer. The documentation is slowly making sense :).

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

UI element highlight OnPointerEnter effected by Hierarchy order of children? 1 Answer

UI Refresh Issues 1 Answer

Please help with player selection screen 2 Answers

Is it possible to pick up "mouse up" on value changed ? 1 Answer

UI Click pass through 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