Before updating to Windows 10 you may need to return your Pro license. More information here

Check if two strings are the same

i'm making a system where you have to enter a code to go to a specific level, but i can't seem to figure out how to check if the string filled in in the textfield is the same as the "correct code" variable. Here's my current script:

 var stringToEdit : String = "Hello World";
 private var positL = Screen.width / 2;
 private var PositT = Screen.height / 2;
 function OnGUI () {
 // Make a text field that modifies stringToEdit.
 stringToEdit = GUI.TextField (Rect (positL, PositT, 200, 20), stringToEdit, 25);
 function Update ()
     if(stringToEdit == 4040 && Input.GetKey("Space")){
         Application.LoadLevel (1);
more ▼

asked Sep 20, 2011 at 11:41 AM

avatar image

Raymond 2
174 107 77 88

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Ah- the issue is that GUI.TextField steals all of your keyboard inputs, so the Input.GetKey doesn't trigger because it gets interpreted as a space in your text box! Try using a GUI.Button next to the text field, instead- or set

Input.eatKeyPressOnTextFieldFocus = false;

to disable the 'input-eating' function temporarily.

more ▼

answered Sep 20, 2011 at 11:49 AM

avatar image

19.4k 24 46 157

And to fix the actual problem you have to compare the string with a string:

 if(stringToEdit == "4040")
Sep 20, 2011 at 12:31 PM Bunny83
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Sep 20, 2011 at 11:41 AM

Seen: 2507 times

Last Updated: Sep 20, 2011 at 12:31 PM