Making a GUI text disappear with a tap, FPS look around with finger

Hi, I have this script, which when a specific object is tapped, it creates a nice GUI textbox. The issue is, I then want the textbox to disappear when tapped, or when the screen is tapped elsewhere. I’ve had no luck in figuring it out.

var turret: GameObject;
private var showBox = false;
var boxwidth: int = 300;
var boxheight: int = 300;
var boxfromleft: int = 500;
var boxfromright: int = 500;

function Update () {

for (var touch : Touch in Input.touches) {
	if (touch.phase == TouchPhase.Began) {
	
	var ray = Camera.main.ScreenPointToRay (touch.position);
	
	if (Physics.Raycast (ray)) {
		showBox = true;
		
		}
	}
}

}

function OnGUI () {
if (showBox)

GUI.Box (Rect (boxfromleft,boxfromright,boxwidth,boxheight), "A classic Neo-Victorian Turret");

}

Also, I also I have been trying to get a first person look around script, that when a camera in enabled in the first person view, dragging a finger around the screen allows you to look around. I’ve tried modifying the first person iPhone controls, to just have the right side joystick working because thats all I need.

Any help is much appreciated!
Thanks
K.

My answer is related to your first question. Maybe you should split your questions into two posts. Anyway… Have you tried storing the textbox rectangle and using Rect.contains to see if the mouse is within the textboxs’ rectangle or out of the rectangle when the mouse is pressed or finger taps? Look at http://unity3d.com/support/documentation/ScriptReference/Rect.Contains.html

Edit: Try this code and check logging to see what is happening

var rect = Rect(boxfromleft,boxfromright,boxwidth,boxheight);

if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) 
{ 
	if (showBox == false)
	{
		var ray = Camera.main.ScreenPointToRay (Input.GetTouch(0).position); 
		var hit: RaycastHit; 
		
		if(Physics.Raycast (ray,hit,10000) && hit.collider.gameObject.tag == "rightturret")
		{
			showBox = true;
			Debug.Log("Box should be displayed");
		}
	}
	else
	{
		if  (!rect.Contains(Input.GetTouch(0).position))
		{
			showBox = false;
			Debug.Log("Box should be hidden");
		}
	}
}

function Update () {

var ray = Camera.main.ScreenPointToRay (Input.GetTouch(0).position);
var hit: RaycastHit;
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
{
if (Physics.Raycast (ray,hit,10000))
if (hit.collider.gameObject.tag == “rightturret”)
{
showBox = true;

            var rect = Rect(boxfromleft,boxfromright,boxwidth,boxheight);
            if (rect.Contains(Input.GetTouch(0).position)) 
                {
                showBox = false;
            }   
        }
    }
}

I’ve updated to the following code, with no errors, however it will not make the GUI.box disappear yet. Thoughts?

Thanks again for your input! K.