- Home /
 
               Question by 
               Pebam · Sep 14, 2016 at 12:25 PM · 
                guiraycastraycasthit  
              
 
              How to get raycast hit coordinates on Cardboard
The following script is attached to a color picker object in my Unity setup for Google Cardboard. On hover on the color picker,  , I want to get the coordinates of where the Raycast hits the collider (so that I can get the color in that coordinate).
, I want to get the coordinates of where the Raycast hits the collider (so that I can get the color in that coordinate).
Question 1: On the FixedUpdate, I've an if statement if (GetComponent<Collider>().Raycast(ray, out hit, 100)) and it's returning false. What am I missing here?
Question 2: Am I correct to assume that if the hit.point is set, I could get the x,y,z coordinates of the point where the ray hits the collider to be point.x, point.y and point.z?
 public class ColorPicker : MonoBehaviour {
 
     public Camera CameraRay;
     public Vector3 screenPos;
 
 
     void FixedUpdate(){ 
 
         Ray ray = new Ray (CameraRay.transform.position, CameraRay.transform.forward);
         RaycastHit hit;
         if (GetComponent<Collider>().Raycast(ray, out hit, 100)) {
             Debug.Log ("True");
                     Vector3 point = camera.WorldToScreenPoint(hit.point);
         } else {
             Debug.Log ("False");
         }
 
     }
 }
 
                 
                wheelpicker.png 
                (48.6 kB) 
               
 
              
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                