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
1
Question by StarlingSoftworksInteractive · Nov 09, 2017 at 08:40 PM · unity 5

There is an error with onEndEdit with the inputfield

Hi there, I am trying to get what the user types into input field, but there an error. I have also put using using UnityEngine.UI; as well but with no luck. The error is this:

Assets/InputField.cs(18,20): error CS1061: Type InputField' does not contain a definition for onEndEdit' and no extension method onEndEdit' of type InputField' could be found. Are you missing an assembly reference?

 public InputField inputfield;
     private Dictionary<string, System.Action<string, string>> commands;
 
     protected void Awake()
     {
         commands = new Dictionary<string, System.Action<string, string>>();
         // Add the commands you want to recognise along with the functions to call
         commands.Add("new game", OnNewGameTyped);
         commands.Add("hello", OnHelloTyped);
         // Listen when the inputfield is validated
         inputfield.onEndEdit.AddListener(OnEndEdit);
     }
 
     private void OnEndEdit(string input)
     {
         // Only consider onEndEdit if the Submit button has been pressed
         if (!Input.GetButtonDown("Submit"))
             return;
 
         bool commandFound = false;
 
         // Find the command
         foreach (var item in commands)
         {
             if (item.Key.ToLower().StartsWith(input.ToLower()))
             {
                 commandFound = true;
                 item.Value(item.Key, input);
                 break;
             }
         }
 
         // Do something if the command has not been found
         if (!commandFound)
             Debug.Log("No command found");
 
         // Clear the input field (if you want)
         //inputfield.text = "";
     }
 
     private void OnNewGameTyped(string command, string input)
     {
         Debug.Log("Starting new game");
         UnityEngine.SceneManagement.SceneManager.LoadScene(1);
     }
 
     private void OnHelloTyped(string command, string input)
     {
         Debug.Log("Hello my friend !");
     }
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
Best Answer

Answer by Bunny83 · Nov 09, 2017 at 08:53 PM

You named your own class "InputField". So you're hiding the class that is defined inside the UnityEngine.UI namespace. That means your public variable public InputField inputfield; is actually your own class type and not the UI.InputField.

Either rename your own class / script or use

 public UnityEngine.UI.InputField inputfield;
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 StarlingSoftworksInteractive · Nov 10, 2017 at 12:30 AM 0
Share

Thanks for that, I can't believe I totally miss that

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

145 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

Related Questions

Script editor not recognising Unity specific code?! 0 Answers

how to get an image when button is pressed.......lyk in game rps when we click rock it should show the image of the rock......how do i access them....thnks for helping!!] 0 Answers

One Button Game project : two types of input on the same button 0 Answers

Multitouch on Android: position incorrect 0 Answers

error when build .apk 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