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
0
Question by TheFrankman123 · Apr 12, 2012 at 06:42 PM · stringonguitextfield

how to check GUI.TextField Entry

Right, basic question. Don't normally ask questions like this but don't know where to start.

So i know how to make a text field that can be filled in. Simple stuff.

I am making a code entry. So someone finds a code in the level and has to input it in order to proceed.

What do i need to look into in order to check if what has been entered into the text field is correct.

Not asking anyone to do it for me, just want to know what i have to look at in the script reference. But any code to get me kicked off would be appriciated

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
1
Best Answer

Answer by TheFrankman123 · Apr 12, 2012 at 09:34 PM

I figured this out. My problem was that you need to check if stringToEding is the value inside the update not the function itself. Was me being stupid. So it would work as follows:

 private var stringToEdit : String = "Enter Code";
 
 function OnGUI () {
     
     if(enableGUI == true) {
     
         stringToEdit = GUI.TextField (Rect (10, 10, 200, 20), stringToEdit, 25);
 
     }    
         
 }
            
 
 function Update () {
     
     if(stringToEdit == "1234") { 
     Debug.Log("code correct");    
         
     }    
 }
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 davedx · Apr 12, 2012 at 06:44 PM

Here is the docs for TextField: http://unity3d.com/support/documentation/ScriptReference/GUI.TextField.html

There's an example that shows you how to use it. Basically, all of the Unity GUI's operate in an 'immediate mode' - you call the controls as a static function and immediately receive whatever input they've received as a return value. You should put them all in your OnGUI() function (or functions called from it). Note: OnGUI() is called more than once every frame.

Good luck!

Comment
Add comment · Show 3 · 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 TheFrankman123 · Apr 12, 2012 at 06:51 PM 0
Share

I already have the text field. What i need to do is when you click submit it stores what has been submitted so i can then check if that string = 1234 or whatever i decide the code to be.

So i realise i will have to do something along the lines of:

var stringToEdit : String = "Enter Code"; private var code : String = "1234";

function OnGUI () {

 stringToEdit = GUI.TextField (Rect (10, 10, 200, 20), stringToEdit, 25);
     
     if(GUI.Button(Rect(50,0,60,30),"Submit")) {
          //store as a variable
          //check to see if that varible = code.
     }

}

avatar image rutter · Apr 12, 2012 at 07:03 PM 0
Share

Not sure what you're asking. If you want to know what value has been entered by the user, it's stored in stringToEdit.

GUI.TextField() takes a string argument (text in) and returns a string (text out). If you use the same variable to pass value and store return, it'll basically give you real-time updates. Only problem is if you want to store that value and disallow further changes to it.

avatar image TheFrankman123 · Apr 12, 2012 at 07:10 PM 0
Share

I just want to check if what's been written in the text field is equal to what i want to set the code as.

if i do : if(stringToEdit == code){ or if i do : if(stringToEdit == "1234") {

Then asked it to debug log code correct if this is what's entered. But that doesn't work.

Sorry if this is getting frustrating, but can't really get my head around it.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

TextField Query 1 Answer

GUI set max amount of characters for Label 1 Answer

Changing variables in real time. 2 Answers

TextField moves/jumps when focused 0 Answers

Decreasing Length of a String? 2 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