Obtain a vector3 point in space from a ray hit

forst srry for my english,

im trying to get a point in the space from a ray, but im casting the ray from a touch, so i seach in the scrpt reference and get this code:

    for (var i = 0; i < Input.touchCount; ++i) {
    if (Input.GetTouch(i).phase == TouchPhase.Began) {
        // Construct a ray from the current touch coordinates
        var ray = Camera.main.ScreenPointToRay (Input.GetTouch(i).position);
        if (Physics.Raycast (ray)) {
               //do something
        }
    }

i try to use: RaycastHit.Point for get the point in the space, but this dosnt work…

any can help me whit this?

i really dont understan this line of code, and there is the problem:

            if (Physics.Raycast (ray)) {

thanks

You should define the origin and direction of the ray you’ve created otherwise the raycast will not have a start and a direction Vector3.
Also, you should use a RaycastHit in order to obtain the collision details.

The code will look like so:

for (var i = 0; i < Input.touchCount; ++i) {

     if (Input.GetTouch(i).phase == TouchPhase.Began) {
        
            // Construct a ray from the current touch coordinates
            var ray = Camera.main.ScreenPointToRay (Input.GetTouch(i).position);
            var collider: RaycastHit;
    
            if (Physics.Raycast (ray.origin, ray.direction, collider)) {
                   var collisionPoint: Vector3 = collider.point; // this will hold the exact position of the collision
    
            }
        }