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
5
Question by bannax · Feb 02, 2015 at 08:00 AM · c#inputfield

Get text from Input field in C#

Hi, i'm trying to get a text inside an inputField in Unity3D with C#.

I've placed an inputField in my editor, renamed and tagged in: Username_field.

My question is: How i can get the text inside the inpus Username_field in a C# script?

Thanks :)

Comment
Add comment · Show 1
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 levjackie14 · Feb 11, 2016 at 04:46 PM 0
Share

This works for me.

 using UnityEngine.UI;
      public Text Username_field;
      //then drag and drop the Username_field
      
      string userID = Username_field.text.ToString();

5 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by LukeAntConroy · Feb 02, 2015 at 09:01 AM

Hi there Bannax, I think this should help with what you are trying to do.

http://stackoverflow.com/questions/28273062/get-text-from-input-field-in-unity3d-with-c-sharp

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

Answer by systemicgames · Feb 11, 2016 at 03:50 PM

this isn't C# but I think you are trying to access the input text. I'm not quite sure what you mean but I think I might be able to help. Use the variable UI.InputField. When you do that make sure you assign you InputField gameobject to the variable I.E.

 var textobject : UI.InputField
 
 function Update () {
 if (textobject.text == "hello")
 {
 Application.LoadLevel("Hello")
 }
 }

In that example I checked to make sure that the input field text read "hello" after that I unity load a level called "Hello". In your case if you are trying to make a user name you would need to make the InputField text a string.

I looked around the internet for hours without finding any simple solution for checking the InputField text. I tested the above code out in my own game and it worked. Like I said above I'm not sure what you are trying to do but I hope this helps. If you have any problems please feel free to message me and I will do my best to help you solve them.

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

Answer by levjackie14 · Feb 11, 2016 at 09:35 PM

This works for me.

  using UnityEngine.UI;
       public Text Username_field;
       //then drag and drop the Username_field
       
       string userID = Username_field.text.ToString();

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 Chino_96 · Sep 26, 2017 at 08:45 PM 0
Share

is there a way to use that to fill an input field on the editor?

avatar image
0

Answer by Wolverine-X-man · Oct 27, 2020 at 09:31 AM

 public class test : MonoBehaviour {
     void Start ()
     {
         var input = gameObject.GetComponent<InputField>();
         var se= new InputField.SubmitEvent();
         se.AddListener(SubmitName);
         input.onEndEdit = se;
 
         //or simply use the line below, 
         //input.onEndEdit.AddListener(SubmitName);  // This also works
     }
 
     private void SubmitName(string arg0)
     {
         Debug.Log(arg0);
     }
 }


alt text


cg6zo.gif (39.3 kB)
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
avatar image
0

Answer by Animatick · Sep 26, 2017 at 11:06 PM

Have you checked this out... it may help

link text

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

9 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Making a bubble level (not a game but work tool) 1 Answer

Load Scene with password 3 Answers

How to convert text field to input field and back again? 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