Locking camera on GUITexture, Unlocking when leaving

Basicly, i’ve got a script working so far that when i get near my game object a GUITexture will appear and the camera look locks to make it easier to click the button…

however if i regret and just leave the area, the GUITexture will dissapear as it should however the camera remains locked…

heres the code i have so far.

#pragma strict
var Entrance : Transform;

var guitexture : GUITexture;
function Start(){

	}
	
	function Update () {
	
	var dist : float = Vector3.Distance(Entrance.position, transform.position);
	
	if(dist<10) 
	{
		guitexture.enabled = true;
		Screen.lockCursor = false;
		var firstPersonControllerCamera = gameObject.Find("Player").GetComponent(MouseLook);
   		var mainCamera = gameObject.Find("Main Camera").GetComponent(MouseLook);
		firstPersonControllerCamera.enabled = false;
		mainCamera.enabled = false;
	}
	else{
		guitexture.enabled = false;
		Screen.lockCursor = true;
		firstPersonControllerCamera.enabled = true;
		mainCamera.enabled = true;
		}
	}

I’m not experienced with javascript that much. (I prefer C#) But I expect you need to move the following 2 lines to before the if(dist<10). (Or copy them to the else statement before you use them there)

var firstPersonControllerCamera = gameObject.Find("Player").GetComponent(MouseLook);
var mainCamera = gameObject.Find("Main Camera").GetComponent(MouseLook);

This is because you declare the variable in the if statement.
This is generally a bad practice if you intend to use it outside the if statement. C# will throw a compiler error if you do this. Javascript does not, but usually you get problems like these.