Trying to combine this script for a Security Door Code

I am trying to interact these codes I found to make a door where you have to enter a code before being able to open it. The GUI only pops up when you bump into a collider. I am trying to revamp these codes into one, I am prolly making it a lot harder then need be. Only useful help please, dont be condescending.

Door Script

private var defaultRot : Vector3;
private var openRot : Vector3;

function Start(){
defaultRot = transform.eulerAngles;
openRot = new Vector3 (defaultRot.x, defaultRot.y + DoorOpenAngle, defaultRot.z);
}

//Main function
function Update (){
if(open){
//Open door
transform.eulerAngles = Vector3.Slerp(transform.eulerAngles, openRot, Time.deltaTime * smooth);
}else{
//Close door
transform.eulerAngles = Vector3.Slerp(transform.eulerAngles, defaultRot, Time.deltaTime * smooth);
}

if(Input.GetKeyDown(“f”) enter){
open = !open;
}
}

function OnGUI(){
if(enter){
GUI.Label(new Rect(Screen.width/2 - 75, Screen.height - 100, 150, 30), “Press ‘F’ to open the door”);
}
}

//Activate the Main function when player is near the door
function OnTriggerEnter (other : Collider){
if (other.gameObject.tag == “Player”) {
enter = true;
}
}

//Deactivate the Main function when player is go away from door
function OnTriggerExit (other : Collider){
if (other.gameObject.tag == “Player”) {
enter = false;
}
}

Collide Script (Figure I Can Alter This To Let Them Know To Enter The Code)

var myGUIText : GUIText;

function Start ()
{
myGUIText.gameObject.active = false;
}

function OnTriggerEnter()
{
myGUIText.text = “Oops! Dead end. Keep trying!”;
myGUIText.gameObject.active = true;
}

function OnTriggerExit()
{
myGUIText.gameObject.active = false;
}

Door Code

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
}
}

Thank you in advance, I dont want people to write it for me, if you can help me a little please. I am stuck on this part and can not move on with my Horror FPS without this code.

To use code tags just hit Go Advanced at the bottom right. Makes your code easier to read and find errors. Speaking of errors, what kind are u getting? Using print or Debug will help u troubleshoot to see what parts of your script may not be working, then you only need to post the broken / error filled part of the script.

If someone doesn’t beat me to it ill take a look at your script in a min.

Here you go. :smile:

// May not be exactly what you were looking for but has all the features from the examples.

var pWord : String = "1234";
var usePassWord : boolean;
var myGUIText : GUIText;

private var openDoor : boolean;
private var enterZone : boolean;
private var openRot = Vector3(0,120,0);
private var defaultRot = Vector3(0,0,0);
private var doorCode : String = "1234";
private var buttonMessage : String = "Access Denied";
///=========================================================================///
function Start(){
    //------------//
    defaultRot = transform.eulerAngles;
    //------------//
    if(myGUIText) { myGUIText.gameObject.active = false; }
    //------------//
    openRot = new Vector3(defaultRot.x, defaultRot.y + openRot.y, defaultRot.z);
    //------------//
}
///========================================================================================///
function Update (){
	//------------//
	if(openDoor){	
	  transform.eulerAngles = Vector3.Slerp(transform.eulerAngles, openRot, Time.deltaTime * 2); // Open door
	}
	else{
	  transform.eulerAngles = Vector3.Slerp(transform.eulerAngles, defaultRot, Time.deltaTime * 2); // Close door
	}
	//------------// Not being used on a key code door
	if(!usePassWord) {
		if(Input.GetKeyDown("f")  enterZone){
		  openDoor = !openDoor;
		}
	}
	//------------//
}
///========================================================================================///
function OnTriggerEnter (other : Collider){
	//------------//
    if(myGUIText) { myGUIText.text = "Oops! Dead end. Keep trying!"; }
    if(myGUIText) { myGUIText.gameObject.active = true; }
    //------------//
	if (other.gameObject.tag == "Player") {
	  enterZone = true;
	}
	//------------//	
}
///========================================================================================///
function OnTriggerExit (other : Collider){
	//------------//
    if(myGUIText) { myGUIText.text = ""; }
	if(myGUIText) { myGUIText.gameObject.active = false; }
	//------------//
	if (other.gameObject.tag == "Player") {
	  enterZone = false;
	}
	//------------//
}
///========================================================================================///
function OnGUI(){
	//------------//
    pWord = GUI.TextField (Rect (20, 100, 70, 25), pWord, 4);
    //------------//
	if(pWord == doorCode){
	  buttonMessage = "OpenDoor";
	}
	else{
	  buttonMessage = "Access Denied";
	}
	if(GUI.Button(Rect(95, 100, 95, 35), buttonMessage)  pWord == doorCode){
	  openDoor = true;
	}
	//------------//
    if(usePassWord) {
	    if(enterZone){
		  GUI.Label(new Rect(Screen.width/2 - 75, Screen.height - 100, 250, 30), "Enter Key Code Then Press 'F' to open");
		}
	}
	else {
		if(enterZone){
		  GUI.Label(new Rect(Screen.width/2 - 75, Screen.height - 100, 250, 30), "Press 'F' to open the door");
		}
	}
	//------------//
}
///========================================================================================///

Thank you, I am trying to get it to work now. It functions properly I am just trying to adjust it so the GuiText isnt up all the time and the door can close. I do appreciate the help though