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!");
}
}
}
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.