I have a Physics Raycaster attached to the Camera. The Pointer Click Event Trigger is working correctly. However I need to do it from the source code. These are my attempts:
private void SetOnPushButtonFireManager(){
cardboard.OnTrigger += () => {
Debug.Log("Button triggered!");
RaycastHit hit;
// if(Physics.Raycast(headGameObject.GetComponent<GvrHead>().Gaze, out hit, Mathf.Infinity)){
if(Physics.Raycast(cameraGameObject.transform.position, cameraGameObject.transform.forward, out hit, Mathf.Infinity)){
Debug.Log("Collision detected!");
}
};
}
"Button triggered!" is shown in the Console. Unfortunately "Collision detected!" is not. However the Pointer Click Event Trigger is working correctly (the component attached in the inspector). How can I know what is going on? Why isn't it working?
UPDATE: I have answered this answer here: http://answers.unity3d.com/answers/1200449/view.html
(stackoverflow does not allow me to delete this question)
Here's some code I've been using to fire a ray from the camera. I don't have Google Cardboard, this was setup for a camera and a mouse pointer.
// Fire ray from camera
float rayLength = 2f
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
// If ray hits object within length
if (Physics.Raycast(ray, out hit, rayLength))
{
Debug.Log("Collision detected!:);
}