I am trying to determine the object that I touch on the iPhone by casting a ray from the camera position to the touched position on the screen. It does not work. When I dray the ray as a Gizmo, I can see the ray moving outside the game region and also into opposite directions as if the scale and orientation are wrong. What am I doing wrong? Below is the script:
function OnDrawGizmos(){
Gizmos.color = Color.blue;
var touch : iPhoneTouch;
if (iPhoneInput.touchCount > 0) {
touch = iPhoneInput.GetTouch(0);
pos = touch.position;
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(touch.position.x, touch.position.y));
var hit : RaycastHit;
if (Physics.Raycast(ray,hit))
{
Gizmos.DrawCube (hit.point, Vector3(1,1,1));
}
Gizmos.DrawRay (ray.origin, ray.direction * 100);
}
}