Limiting screen area for raycast

hey everyone

say i am using a ray to point for a position of an object,

on my left side of my screen i have a bar full of GUI buttons, lets say the bar is a total of 50 px wide.

my issue is when i tap on the GUI buttons it still calls the ray under it and moves the position of the object.

How can i go about limiting or “ignoring” those 50 pxs of the right side of the screen from the raycast?

put the point to ray function under an if statement that asks if the touch.position is within a rect that is the size and area of the portion of the screen you want to raycast in.

var sideOfScreenRect : Rect; //a rect variable, say Rect(240,0,240,320). just keep in mind the size of the screen of the device your exporting this to.
var theTouchYouWant : Touch; //you don't need this unless you plan on keeping track of multiple touches. if you dont, just set this to 0 and it'll return the first touch on the screen.

if (sideOfScreenRect.Contains(Input.Touches[theTouchYouWant].position) )
{
     //put your point to ray function here
}

this is actually causing my whole unity to crash out lol

here is my exact code. did i implement what you send correctly? the compiler comes up with no errors, but my entire unity crashes when i add what you said to the script

// Prints the name of the object camera is directly looking at

var sideOfScreenRect = Rect(24,0,1000,768);
var theTouchYouWant : Touch = Input.GetTouch(0);
var spawner : Transform;
function Update () {
	
	if (sideOfScreenRect.Contains(Input.touches[theTouchYouWant].position) )
	{
	var touch : Touch = Input.GetTouch(0);
    // Get the ray
    var ray = camera.ScreenPointToRay( Vector3( touch.position.x, touch.position.y ) );
    // Do a raycast
    var hit : RaycastHit;
    if (Physics.Raycast (ray, hit))
	{        
	print ("I'm looking at " + hit.transform.name);
        spawner.position=hit.transform.position;
	}
	
	    else
	    {
        print ("I'm looking at nothing!");
	    }
}
}

fixxed the issue, unity crashed if you have the touch scripting within the contains, mousePosition worked fine

I think what may have been making your game crash is that theTouchYouWant should be an int. my bad. I wrote it wrong in the example code i gave you.
You should probably just try:
if (sideOfScreenRect.Contains(Input.GetTouch(0).position) )

you wont be able to keep track of multiple touches with this method, but it should work fine as long as the player only needs to touch one thing at a time.