Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
0
Question by AlejandroBoss10 · Apr 10, 2018 at 05:55 PM · textif-statementsinputfieldcheck

How to detect certain text in an input field?

Hello everyone, let me get right to it. So you know how many games have a sort of type in cheatcode to unlock stuff, like the cheatcode system in Turok, Need for Speed, and Conker's Bad Fur Day. So what I'm asking is how can I detect a certain input like the word "Unlocked" and have it do something like a Debug.Log. So pretty much like have the input field there. The player types in something specific like "Unlocked" and a debug.log shows up. If they type something else, an error message shows up in a debug.log. I would show a piece of code, but I don't know how to even start with this input field. Any help would be totally appreciated. I will be clearer if needed.

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

2 Replies

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

Answer by Nazirzadeh · Apr 11, 2018 at 12:53 AM

Hi,

 public InputField mainInputField;
 public string myText;

Then inside your function:

   myText=mainInputField.text;
     if(myText == "Unlocked")
     {
       Debug.Log("blah blah");
     }
     else{ 
       Debug.Log(" Blerg!");
     }

Also, take a look at https://stackoverflow.com/questions/28273062/get-text-from-input-field-in-unity3d-with-c-sharp

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 AlejandroBoss10 · Apr 11, 2018 at 07:38 PM 0
Share

This worked pretty well for me. Below is my full code that anyone can use.

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.Scene$$anonymous$$anagement;

public class That : $$anonymous$$onoBehaviour { public InputField mainInputField;

 public string myText; // to show what the text is saying
 public string NewScene; // a string in which you type in the name of ur scene
 public string Cheatcode; // what you want your cheatcode to be

 private void Update()
 {
     Itworked();
 }

 void Itworked()
 {
     myText = mainInputField.text;
     if (myText == Cheatcode)
     {
         //below is where you would put what you want it to do
         Debug.Log("blah blah");
         Scene$$anonymous$$anager.LoadScene(NewScene);

     }
     // feel free to add this if needed
     /* else
   {n nj
   Debug.Log(" Blerg!");
   } */
 }

}

So what I did was I made a script called "That" in Unity. Attached it to the InputField game object. Put my cheatcode name and scene name that I wanted it to load. Then click Play, type in your cheatcode letter by letter, and it should work.

avatar image
0

Answer by burhanasikwala · Nov 25, 2020 at 09:27 AM

It is actually pretty easy.

 using UnityEngine.UI;
 
 class Test : MonoBehaviour
 {
     public InputField inp;
 
     void Update()
     {
         if(inp.text == "text")
         {
             Debug.Log("Player entered 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

81 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

Related Questions

Check if input field is something based on if a text is something 1 Answer

UI InputField text sometimes invisible? 1 Answer

How Does One Make TextMeshPro InputFields Scroll Appropriately When Their Text Components are Bottom-Aligned? 0 Answers

change GUI InputField to TMP_InputField 0 Answers

Changing just the name of person in UI Text 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