Open door with button and textfield question

Hello,

This is very important for my game. i make a button with the name ' open door ' this is the script that a write

function OnGUI () {

  if(GUI.Button(new Rect(95, 100, 95, 35), "open door"))

 animation.Play("port test");
}

and a make a textfiel behind the button. the script

var stringToEdit = "123";

function OnGUI () { // Make a text field that modifies stringToEdit. stringToEdit = GUI.TextField (Rect (20, 100, 70, 25), stringToEdit, 4); }

this is a capture of the result

alt text

So, i have a door in my game that will be open if the player write the right code for example '' 1235 '' and hit open door button. in other way the open door button become true if the player write the right code but if he write another code the button '' open door '' become false. I think that a should use a static var to call one script from another. id don't know how. How to make this work with a javascript. i'm not good at scripting to a found this hard for me. thanks for any help.

To match a string you can use this:

var doorCode : String = "1234";
var stringToEdit : String;
var buttonMessage : String = "Access Denied";

function OnGUI(){
   stringToEdit = GUI.TextField (Rect (20, 100, 70, 25), stringToEdit, 4); 
   if(stringToEdit == doorCode){
      buttonMessage = "OpenDoor";
   }else{
      buttonMessage = "Access Denied";
   }
   if(GUI.Button(Rect(95, 100, 95, 35), buttonMessage) && stringToEdit == doorCode){
      //openDoor
   }
}